<repo_name>AvijitDasAdhikary/laravel8<file_sep>/app/Http/Controllers/TodoController.php
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\Todo;
use Redirect,Response;
use Validator;

class TodoController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        // $todos = Todo::get();
        $todos = Todo::paginate(5);
        return view('todos.todo', compact('todos'));
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        return view('todos.createTodo');
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        $validator = Validator::make($request->all(),[
            'todoName'  =>  'required',
        ],[
            'todoName.required' => 'Please select TodoName',
        ]);

        if ($validator->fails())
        {
            return Response::json(array(
                'success' => false,
                'errors' => $validator->getMessageBag()->toArray()
            ), 400);
        }
        $todos = new Todo();
        $todos->name = $request->todoName;
        $todos->status = $request->todoStatus;
        if ($request->hasFile('inputImage')) {
            $document = $request->file('inputImage');
            $documentExtension = $document->getClientOriginalExtension();
            $documentName = time() . '.' . $documentExtension;
            $path = 'uploads/'.date('Y').'/'.date('m').'/'.date('d');
            $document->move(public_path($path), $documentName);
            $dbDocumentPath = $path.'/'.$documentName;
        }else{
            $dbDocumentPath = '';
        }
        $todos->image = $dbDocumentPath;
        $todos->save();

        return redirect('todos');

    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        $todos = Todo::findOrFail($id);
        return view('todos.edittodo', compact('todos','id'));
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        $todos = Todo::findOrFail($id);

        $todos->name = $request->todoName;
        $todos->status = $request->todoStatus;
        $todos->save();

        return redirect('todos');
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        $todos = Todo::findOrFail($id);
        $todos->delete();

        return Response::json(array('success' => true), 200);   
    }
}
<file_sep>/app/Http/Controllers/FormCodesController.php
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\FormCodes;
use Redirect,Response;
use Illuminate\Support\Facades\Validator;
use App\Models\Department;


class FormCodesController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        $formcodes = FormCodes::with('departmentId')->get();
        return view('form_codes.view', compact('formcodes'));

    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        $departments = Department::get();
        return view('form_codes.create', compact('departments'));
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        validator::make($request->all(),[
            'department' => 'required',
            'formCode' => 'required',
            'formDescription' => 'required',
        ])->validate();

        $formcodes = new FormCodes();
        $formcodes->department_id = $request->department;
        $formcodes->form_code = $request->formCode;
        $formcodes->description = $request->formDescription;
        $formcodes->is_active = $request->formStatus;
        $formcodes->save();

        return redirect('formcodes');
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        $departments = Department::get();
        $formcodes = FormCodes::findOrFail($id);
        return view('form_codes.edit', compact('formcodes','id','departments'));
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        validator::make($request->all(),[
            'department' => 'required',
            'formCode' => 'required',
            'formDescription' => 'required',
        ])->validate();

        $formcodes = FormCodes::findOrFail($id);
        $formcodes->department_id = $request->department;
        $formcodes->form_code = $request->formCode;
        $formcodes->description = $request->formDescription;
        $formcodes->is_active = $request->formStatus;
        $formcodes->save();

        return redirect('formcodes');
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        $formcodes = FormCodes::findOrFail($id);
        $formcodes->delete();

        return Response::json(array('success' => true), 200); 
    }
}
<file_sep>/database/migrations/2021_02_11_143756_create_form_item_options_table.php
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateFormItemOptionsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('form_item_options', function (Blueprint $table) {
            $table->engine = "InnoDB";
            $table->integer('id')->autoIncrement();
            $table->integer('item_id');
            $table->integer('option_id');
            $table->tinyinteger('is_active')->comment('0 => Inactive, 1=> Active');
            $table->foreign('item_id')->references('id')->on('form_items');
            $table->foreign('option_id')->references('id')->on('master_form_options');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('form_item_options');
    }
}
<file_sep>/public/dist/custom/my.js
/* 
 * ***************************************************************
 * Script : 
 * Version : 
 * Date :
 * Author : <NAME>.
 * Email : <EMAIL>
 * Description : 
 * ***************************************************************
 */


function toast(message,title,typemessage = "info"){
    toastr.options = {
            "closeButton": true,
            "debug": false,
            "newestOnTop": true,
            "progressBar": true,
            "positionClass": "toast-top-right",
            "preventDuplicates": false,
            "onclick": null,
            "showDuration": "300",
            "hideDuration": "1000",
            "timeOut": "5000",
            "extendedTimeOut": "1000",
            "showEasing": "swing",
            "hideEasing": "linear",
            "showMethod": "fadeIn",
            "hideMethod": "fadeOut"
        };
    toastr[typemessage](title,message);
}

function data_terbilang(bilangan) {
 
 if(bilangan==="" || bilangan==="0"){
     return "Nol Rupiah";
 }
 
 bilangan    = String(bilangan);
 var angka   = new Array('0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0');
 var kata    = new Array('','Satu','Dua','Tiga','Empat','Lima','Enam','Tujuh','Delapan','Sembilan');
 var tingkat = new Array('','Ribu','Juta','Milyar','Triliun');
 
 var panjang_bilangan = bilangan.length;
 
 /* pengujian panjang bilangan */
 if (panjang_bilangan > 15) {
   kaLimat = "Diluar Batas";
   return kaLimat;
 }
 
 /* mengambil angka-angka yang ada dalam bilangan, dimasukkan ke dalam array */
 for (i = 1; i <= panjang_bilangan; i++) {
   angka[i] = bilangan.substr(-(i),1);
 }
 
 i = 1;
 j = 0;
 kaLimat = "";
 
 
 /* mulai proses iterasi terhadap array angka */
 while (i <= panjang_bilangan) {
 
   subkaLimat = "";
   kata1 = "";
   kata2 = "";
   kata3 = "";
 
   /* untuk Ratusan */
   if (angka[i+2] != "0") {
     if (angka[i+2] == "1") {
       kata1 = "Seratus";
     } else {
       kata1 = kata[angka[i+2]] + " Ratus";
     }
   }
 
   /* untuk Puluhan atau Belasan */
   if (angka[i+1] != "0") {
     if (angka[i+1] == "1") {
       if (angka[i] == "0") {
         kata2 = "Sepuluh";
       } else if (angka[i] == "1") {
         kata2 = "Sebelas";
       } else {
         kata2 = kata[angka[i]] + " Belas";
       }
     } else {
       kata2 = kata[angka[i+1]] + " Puluh";
     }
   }
 
   /* untuk Satuan */
   if (angka[i] != "0") {
     if (angka[i+1] != "1") {
       kata3 = kata[angka[i]];
     }
   }
 
   /* pengujian angka apakah tidak nol semua, lalu ditambahkan tingkat */
   if ((angka[i] != "0") || (angka[i+1] != "0") || (angka[i+2] != "0")) {
     subkaLimat = kata1+" "+kata2+" "+kata3+" "+tingkat[j]+" ";
   }
 
   /* gabungkan variabe sub kaLimat (untuk Satu blok 3 angka) ke variabel kaLimat */
   kaLimat = subkaLimat + kaLimat;
   i = i + 3;
   j = j + 1;
 
 }
 
 /* mengganti Satu Ribu jadi Seribu jika diperlukan */
 if ((angka[5] == "0") && (angka[6] == "0")) {
   kaLimat = kaLimat.replace("Satu Ribu","Seribu");
 }
 
 return kaLimat + "Rupiah";
}

function set_date(tahun,bulan,hari){    
    var d = new Date();
    
    if(Number(tahun) > d.getFullYear()){
        tahun = 0;
    }
    
    if(!(bulan)){
        bulan = 12;
    }else if(Number(bulan) === 0 && isNaN(bulan) === false){
        bulan = d.getMonth() + 1;
    }else if(Number(bulan) > 0 && isNaN(bulan) === false){
        bulan = (d.getMonth() - Number(bulan));
    }else if(Number(bulan) > 12 && isNaN(bulan) === false){
        bulan = 12;
    }else{
        bulan = 12;
    }
    
    if(!(hari)){
        hari = 31;
    }else if(Number(hari) === 0 && isNaN(bulan) === false){
        hari = d.getDate();
    }else if(Number(hari) > 0 && isNaN(bulan) === false){
        hari = d.getDate() - Number(hari);
    }else if(Number(hari) > 31 && isNaN(bulan) === false){
        hari = 31;
    }else{
        hari = 31;
    }
    
    
    var res = d.setFullYear(d.getFullYear() - Number(tahun));
    var newyear = new Date(res);
    var resdate = Number(hari) + "/" + Number(bulan) + "/" + newyear.getFullYear();
    return resdate;
}

var substringMatcher = function(strs) {
    return function findMatches(q, cb) {
      var matches, substringRegex;

      // an array that will be populated with substring matches
      matches = [];

      // regex used to determine if a string contains the substring `q`
      substrRegex = new RegExp(q, 'i');

      // iterate through the pool of strings and for any string that
      // contains the substring `q`, add it to the `matches` array
      $.each(strs, function(i, str) {
        if (substrRegex.test(str)) {
          matches.push(str);
        }
      });

      cb(matches);
    };
  };<file_sep>/app/Http/Controllers/FormItemController.php
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\FormItem;
use App\Models\FormSection;
use App\Models\Forms;
use Redirect,Response;
use Illuminate\Support\Facades\Validator;

class FormItemController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        $formitems = FormItem::with('formSectionId')->get();
        return view('form_item.view', compact('formitems'));
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        $forms = Forms::get();
        $formsections = FormSection::get();
        return view('form_item.create',compact('formsections','forms'));
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        validator::make($request->all(),[
            'sectionTitle' => 'required',
            'formItemTitle' => 'required',
            'formItemPoint' => 'required',
            'formItemComment' => 'required',
            'formItemPicture1' => 'required',
            'formItemPicture2' => 'required',
        ])->validate();

        $formitems = new FormItem();
        $formitems->section_id = $request->sectionTitle;
        $formitems->title = $request->formItemTitle;
        $formitems->points = $request->formItemPoint;
        $formitems->is_comment = $request->formItemComment;
        $formitems->is_picture_1 = $request->formItemPicture1;
        $formitems->is_picture_2 = $request->formItemPicture2;
        $formitems->is_active = $request->formItemStatus;
        $formitems->save();

        return redirect('formitem');
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        $forms = Forms::get();
        $formsections = FormSection::get();
        $formitems = FormItem::findOrFail($id);
        return view('form_item.edit', compact('formitems','id','formsections','forms'));
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        validator::make($request->all(),[
            'sectionTitle' => 'required',
            'formItemTitle' => 'required',
            'formItemPoint' => 'required',
            'formItemComment' => 'required',
            'formItemPicture1' => 'required',
            'formItemPicture2' => 'required',
        ])->validate();

        $formitems = FormItem::findOrFail($id);
        $formitems->section_id = $request->sectionTitle;
        $formitems->title = $request->formItemTitle;
        $formitems->points = $request->formItemPoint;
        $formitems->is_comment = $request->formItemComment;
        $formitems->is_picture_1 = $request->formItemPicture1;
        $formitems->is_picture_2 = $request->formItemPicture2;
        $formitems->is_active = $request->formItemStatus;
        $formitems->save();

        return redirect('formitem');
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        $formitems = FormItem::findOrFail($id);
        $formitems->delete();

        return Response::json(array('success' => true), 200); 
    }

    public function getFormTitle($formId){
        $formtitles = FormSection::where(['form_id'=>$formId])->get();
        $returndata = [];
        foreach($formtitles as $formtitle){
            $returndata[] = [
                'id' => $formtitle->id,
                'title' => $formtitle->section_title,
            ];
        }
        return Response::json($returndata,200);
    }
}
<file_sep>/routes/web.php
<?php

use Illuminate\Support\Facades\Route;

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

// Route::get('/', function () {
//     return view('welcome');
// });
Route::get('/home','DeveloperController@index');

Route::get('/dashboard','DashboardController@index');
Route::get('/task','DashboardController@task');

Route::get('/developer','DeveloperController@index');

Route::resources([
    'photos' => PhotoController::class,
    'todos' => TodoController::class,
    'departments' => DepartmentController::class,
    'masterformoptions' => MasterFormOptionsController::class,
    'formcodes' => FormCodesController::class,
    'forms' => FormsController::class,
    'formsection' => FormSectionController::class,
    'formitem' => FormItemController::class,
    'formitemcodes' => FormItemCodeController::class,
    'formitemoptions' => FormItemOptionController::class,
]);

Route::post('formitem/create/{formId}', ['uses' => 'FormItemController@getFormTitle']);
Route::post('formitemcodes/create/formSection/{formId}', ['uses' => 'FormItemCodeController@getFormTitle']);
Route::post('formitemcodes/create/formItem/{SectionId}', ['uses' => 'FormItemCodeController@getSectionTitle']);
Route::post('formitemcodes/create/formCode/{CodeId}', ['uses' => 'FormItemCodeController@getformItemTitle']);

Route::post('formitemoptions/create/formSection/{formId}', ['uses' => 'FormItemOptionController@getFormTitle']);
Route::post('formitemoptions/create/formItem/{SectionId}', ['uses' => 'FormItemOptionController@getSectionTitle']);<file_sep>/app/Http/Controllers/DepartmentController.php
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\Department;
use Redirect,Response;
use Illuminate\Support\Facades\Validator;

class DepartmentController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        $departments = Department::get();
        return view('departments.view', compact('departments'));

    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        return view('departments.create');
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        Validator::make($request->all(),[
            'departmentName' => 'required|unique:departments,name',
            'departmentAlias' => 'required|unique:departments,alias',
        ])->validate();

        $departments = new Department();
        $departments->name = $request->departmentName;
        $departments->alias = $request->departmentAlias;
        $departments->description = $request->departmentDescription;
        $departments->is_active  = $request->departmentStatus;
        $departments->save();

        return redirect('departments');
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        $departments = Department::findOrFail($id);
        return Response::json(array(
            'success' => true,
            'departments' => $departments,
        ), 200);
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        $departments = Department::findOrFail($id);
        return view('departments.edit', compact('departments','id'));
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        Validator::make($request->all(),[
            'departmentName' => 'required|unique:departments,name,'.$id,
            'departmentAlias' => 'required|unique:departments,alias,'.$id,
             // 'departmentDescription' => 'required',
        ])->validate();

        $departments = Department::findOrFail($id);
        $departments->name = $request->departmentName;
        $departments->alias = $request->departmentAlias;
        $departments->description = $request->departmentDescription;
        $departments->is_active = $request->departmentStatus;
        $departments->save();

        return redirect('departments');
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        $departments = Department::findOrFail($id);
        $departments->delete();

        return Response::json(array('success' => true), 200); 
    }
}
<file_sep>/app/Http/Controllers/DashboardController.php
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class DashboardController extends Controller
{
    public function index(){
        $records1 = ['record1'];
        $records2 = [];
        $value = 4;

        $users = [
            ['id'=>1, 'code'=>'DEVELOPER', 'age'=> 25],
            ['id'=>2, 'code'=>'HR', 'age'=> 52],
            ['id'=>3, 'code'=>'Accounts', 'age'=> 62],
            ['id'=>4, 'code'=>'Manager', 'age'=> 46],
        ];

        $admins = [
            ['name'=>'ADMIN', 'status'=> 'Active'],
        ];
        
        return view('dashboard',compact('records1','records2','value','users','admins'));
    }

    public function task(){
        $tasks = ['task1','task2','task3'];
        $tasks2 = ['list1','list2','list3'];

        return view('task', compact('tasks','tasks2'));
    }
}
<file_sep>/app/Http/Controllers/FormSectionController.php
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\FormSection;
use App\Models\Forms;
use Redirect,Response;
use Illuminate\Support\Facades\Validator;

class FormSectionController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        $formsections = FormSection::with('formId')->get();
        return view('form_section.view', compact('formsections'));
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        $forms = Forms::get();
        return view('form_section.create', compact('forms'));
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        validator::make($request->all(),[
            'formTitle' => 'required',
            'sectionTitle' => 'required',
            'parentID' => 'required',
        ])->validate();

        $formsections = new FormSection();
        $formsections->form_id = $request->formTitle;
        $formsections->section_title = $request->sectionTitle;
        $formsections->parent_id = $request->parentID;
        $formsections->is_active = $request->sectionStatus;
        $formsections->save();

        return redirect('formsection');
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        $forms = Forms::get();
        $formsections = FormSection::findOrFail($id);
        return view('form_section.edit', compact('formsections','id','forms'));
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        validator::make($request->all(),[
            'formTitle' => 'required',
            'sectionTitle' => 'required',
            'parentID' => 'required',
        ])->validate();
        
        $formsections = FormSection::findOrFail($id);
        $formsections->form_id = $request->formTitle;
        $formsections->section_title = $request->sectionTitle;
        $formsections->parent_id = $request->parentID;
        $formsections->is_active = $request->sectionStatus;
        $formsections->save();

        return redirect('formsection');
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        $formsections = FormSection::findOrFail($id);
        $formsections->delete();

        return Response::json(array('success' => true), 200); 
    }
}
<file_sep>/app/Models/FormSection.php
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class FormSection extends Model
{
    //use HasFactory;
    use SoftDeletes;
    protected $table = 'forms_sections';

    public function formId()
    {
        return $this->belongsTo('App\Models\Forms','form_id');
    }
}
<file_sep>/app/Models/FormItemOption.php
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class FormItemOption extends Model
{
    //use HasFactory;
    protected $table = 'form_item_options';

    public $timestamps = false;

    public function ItemId()
    {
        return $this->belongsTo('App\Models\FormItem','item_id');
    }

    public function OptionId()
    {
       return $this->belongsTo('App\Models\masterFormOptions','option_id');
    }
}
<file_sep>/app/Models/FormItem.php
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class FormItem extends Model
{
    //use HasFactory;
    use SoftDeletes;

    protected $table = 'form_items';

    public function formSectionId()
    {
        return $this->belongsTo('App\Models\FormSection','section_id');
    }
}
<file_sep>/app/Http/Controllers/FormItemCodeController.php
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\FormItemCode;
use App\Models\FormItem;
use App\Models\FormCodes;
use App\Models\Forms;
use App\Models\FormSection;
use Redirect,Response;
use Illuminate\Support\Facades\Validator;

class FormItemCodeController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        $formitemcodes = FormItemCode::with('formItemId','formCodeId')->get();
        return view('form_item_codes.view', compact('formitemcodes'));
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        $forms = Forms::get();
        $formsections = FormSection::get();
        $formitems = FormItem::get();
        $formcodes = FormCodes::get();
        return view('form_item_codes.create',compact('formitems','formcodes','forms','formsections'));
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        validator::make($request->all(),[
            'formItemTitle' => 'required',
            'formCode' => 'required',
        ])->validate();

        $formitemcodes = new FormItemCode();
        $formitemcodes->item_id = $request->formItemTitle;
        $formitemcodes->code_id = $request->formCode;
        $formitemcodes->is_active = $request->formItemCodeStatus;
        $formitemcodes->save();

        return redirect('formitemcodes');
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        $formitems = FormItem::get();
        $formcodes = FormCodes::get();
        $formitemcodes = FormItemCode::findOrFail($id);
        return view('form_item_codes.edit', compact('formitemcodes','id','formitems','formcodes'));
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        validator::make($request->all(),[
            'formItemTitle' => 'required',
            'formCode' => 'required',
        ])->validate();

        $formitemcodes = FormItemCode::findOrFail($id);
        $formitemcodes->item_id = $request->formItemTitle;
        $formitemcodes->code_id = $request->formCode;
        $formitemcodes->is_active = $request->formItemCodeStatus;
        $formitemcodes->save();

        return redirect('formitemcodes');
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        $formitemcodes = FormItemCode::findOrFail($id);
        $formitemcodes->delete();

        return Response::json(array('success' => true), 200); 
    }

    public function getFormTitle($formId){
        $formtitles = FormSection::where(['form_id'=>$formId])->get();
        $returndata = [];
        foreach($formtitles as $formtitle){
            $returndata[] = [
                'id' => $formtitle->id,
                'title' => $formtitle->section_title,
            ];
        }
        return Response::json($returndata,200);
    }

    public function getSectionTitle($SectionId){
        $formsections = FormItem::where(['section_id'=>$SectionId])->get();
        $returndata = [];
        foreach($formsections as $formsection){
            $returndata[] = [
                'id' => $formsection->id,
                'title' => $formsection->title,
            ];
        }
        return Response::json($returndata,200);
    }

    public function getformItemTitle($CodeId){
        $formcodes = FormCodes::where(['id'=>$CodeId])->get();
        $returndata = [];
        foreach($formcodes as $formcode){
            $returndata[] = [
                'id' => $formcode->id,
                'form_code' => $formcode->form_code,
            ];
        }
        return Response::json($returndata,200);
    }
}
<file_sep>/app/Http/Controllers/MasterFormOptionsController.php
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\masterFormOptions;
use Redirect,Response;
use Illuminate\Support\Facades\Validator;

class MasterFormOptionsController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        $masterformoptions = masterFormOptions::get();
        return view('master_form_options.view', compact('masterformoptions'));

    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        return view('master_form_options.create');
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        Validator::make($request->all(),[
            'masterFormLabel' => 'required|unique:master_form_options,label',
            'inputColorCode' => 'required|unique:master_form_options,color_code'
            ],[
                'inputColorCode.required' => 'Please select a color',
                'inputColorCode.unique' => 'duplicate'
        ])->validate();
        

        $masterformoptions = new masterFormOptions();
        $masterformoptions->label = $request->masterFormLabel;
        $masterformoptions->color_class = $request->masterFormColorClass;
        $masterformoptions->color_code = $request->inputColorCode;
        $masterformoptions->is_active  = $request->masterFormStatus;
        $masterformoptions->save();

        return redirect('masterformoptions');
    }

    /**
     * Display the specified resource.
     *
     * @param  \App\Models\masterFormOptions  $masterFormOptions
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        $masterformoptions = masterFormOptions::findOrFail($id);
        return Response::json(array(
            'success' => true,
            'masterformoptions' => $masterformoptions,
        ), 200);
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  \App\Models\masterFormOptions  $masterFormOptions
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        $masterformoptions = masterFormOptions::findOrFail($id);
        return view('master_form_options.edit', compact('masterformoptions','id'));
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \App\Models\masterFormOptions  $masterFormOptions
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        Validator::make($request->all(),[
            'masterFormLabel' => 'required',
            'inputColorCode' => 'required'
            ],[
                'inputColorCode.required' => 'Please select a color',
                'inputColorCode.unique' => 'duplicate'
        ])->validate();
        
        $masterformoptions = masterFormOptions::findOrFail($id);
        $masterformoptions->label = $request->masterFormLabel;
        $masterformoptions->color_class = $request->masterFormColorClass;
        $masterformoptions->color_code = $request->inputColorCode;
        $masterformoptions->is_active = $request->masterFormStatus;
        $masterformoptions->save();

        return redirect('masterformoptions');
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  \App\Models\masterFormOptions  $masterFormOptions
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        $masterformoptions = masterFormOptions::findOrFail($id);
        $masterformoptions->delete();

        return Response::json(array('success' => true), 200); 
    }
}
<file_sep>/app/Http/Controllers/FormsController.php
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\Forms;
use App\Models\Department;
use Redirect,Response;
use Illuminate\Support\Facades\Validator;

class FormsController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        $forms = Forms::with('departmentId')->get();
        return view('forms.view', compact('forms'));
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        $departments = Department::get();
        return view('forms.create',compact('departments'));
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        validator::make($request->all(),[
            'department' => 'required',
            'formTitle' => 'required',
            'formsDescription' => 'required',
        ])->validate();

        $forms = new Forms();
        $forms->department_id = $request->department;
        $forms->title = $request->formTitle;
        $forms->description = $request->formsDescription;
        $forms->is_active = $request->formStatus;
        $forms->save();

        return redirect('forms');
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        $departments = Department::get();
        $forms = Forms::findOrFail($id);
        return view('forms.edit', compact('forms','id','departments'));
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        validator::make($request->all(),[
            'department' => 'required',
            'formTitle' => 'required|unique:forms,title,'.$id,
            'formsDescription' => 'required',
        ])->validate();
        
        $forms = Forms::findOrFail($id);
        $forms->department_id = $request->department;
        $forms->title = $request->formTitle;
        $forms->description = $request->formsDescription;
        $forms->is_active = $request->formStatus;
        $forms->save();

        return redirect('forms');
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        $forms = Forms::findOrFail($id);
        $forms->delete();

        return Response::json(array('success' => true), 200); 
    }
}
<file_sep>/database/migrations/2021_02_11_143949_create_form_item_codes_table.php
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateFormItemCodesTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('form_item_codes', function (Blueprint $table) {
            $table->engine = "InnoDB";
            $table->integer('id')->autoIncrement();
            $table->integer('item_id');
            $table->integer('code_id');
            $table->tinyInteger('is_active')->comment('0 => Inactive, 1 => Active');
            $table->foreign('item_id')->references('id')->on('form_items');
            $table->foreign('code_id')->references('id')->on('form_codes');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('form_item_codes');
    }
}
<file_sep>/app/Http/Controllers/FormItemOptionController.php
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\FormItemOption;
use App\Models\FormItem;
use App\Models\masterFormOptions;
use App\Models\Forms;
use App\Models\FormSection;
use Redirect,Response;
use Illuminate\Support\Facades\Validator;

class FormItemOptionController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        $formitemoptions = FormItemOption::with('ItemId','OptionId')->get();
        return view('form_item_options.view',compact('formitemoptions'));
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        $forms = Forms::get();
        $formsections = FormSection::get();
        $formitems = FormItem::get();
        $masterformoptions = masterFormOptions::get();
        return view('form_item_options.create',compact('formitems','masterformoptions','forms','formsections'));
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        validator::make($request->all(),[
            'formItemTitle' => 'required',
            'masterFormLabel' => 'required',
        ])->validate();
        
        $option_id = $request->input('masterFormLabel'); 
        foreach($option_id as $option)
        {
            $formitemoptions = new FormItemOption();
            $formitemoptions->item_id = $request->formItemTitle;
            $formitemoptions->option_id = $option;
            $formitemoptions->is_active = $request->formItemOptionStatus;
            $formitemoptions->save();
        }
        return redirect('formitemoptions');
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        $formitems = FormItem::get();
        $masterformoptions = masterFormOptions::get();
        $formitemoptions = FormItemOption::findOrFail($id);
        return view('form_item_options.edit', compact('formitemoptions','id','formitems','masterformoptions'));
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        validator::make($request->all(),[
            'formItemTitle' => 'required',
            'masterFormLabel' => 'required',
        ])->validate();

        $option_id = $request->input('masterFormLabel'); 
        foreach($option_id as $option)
        {
            $formitemoptions = FormItemOption::findOrFail($id);
            $formitemoptions->item_id = $request->formItemTitle;
            $formitemoptions->option_id = $option;
            $formitemoptions->is_active = $request->formItemOptionStatus;
            $formitemoptions->save();
        }

        return redirect('formitemoptions');
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        $formitemoptions = FormItemOption::findOrFail($id);
        $formitemoptions->delete();

        return Response::json(array('success' => true), 200); 
    }

    public function getFormTitle($formId){
        $formtitles = FormSection::where(['form_id'=>$formId])->get();
        $returndata = [];
        foreach($formtitles as $formtitle){
            $returndata[] = [
                'id' => $formtitle->id,
                'title' => $formtitle->section_title,
            ];
        }
        return Response::json($returndata,200);
    }

    public function getSectionTitle($SectionId){
        $formsections = FormItem::where(['section_id'=>$SectionId])->get();
        $returndata = [];
        foreach($formsections as $formsection){
            $returndata[] = [
                'id' => $formsection->id,
                'title' => $formsection->title,
            ];
        }
        return Response::json($returndata,200);
    }
}
<file_sep>/app/Models/FormItemCode.php
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class FormItemCode extends Model
{
    //use HasFactory;
    protected $table = 'form_item_codes';
    public $timestamps = false;

    public function formItemId()
    {
        return $this->belongsTo('App\Models\FormItem','item_id');
    }

    public function formCodeId()
    {
        return $this->belongsTo('App\Models\FormCodes','code_id');
    }
}
