mardi 11 octobre 2016

How to solve undefined variable error in Laravel 5

I currently develop a file manager website with Laravel 5 but when I tried to open it from localhost, i found this

ErrorException in 67894396baa5cb5f4018acaa490f70c8 line 194: Undefined variable: sharedToBadanPembina (View: C:\xampp\htdocs\laravel\manager_edit\resources\views\file_modals.blade.php)

Here's routes.php

Route::get('filemanager', 'FileController@index')->name('filemanager');
Route::post('filemanager/file', 'FileController@uploadFile');
Route::post('filemanager/folderShare', 'FileController@shareFolder');
Route::delete('filemanager/file', 'FileController@deleteFile');
Route::post('filemanager/folder', 'FileController@createFolder');
Route::delete('filemanager/folder', 'FileController@deleteFolder');
Route::get('filemanager/download/{filePath}','FileController@downloadFile')->name('download');
Route::get('filemanager/search','FileController@search')->name('filemanager/search');
Route::get('filemanager/viewsearch','FileController@viewSearch')->name('filemanager/videwsearch');

I think there's something error with index function because it still shows the same result eventhough I tried to comment all of it. I have tried with middleware but it gives nothing.

FileController.php

    public function index(Request $request)
    {
        $folder = $request::get('folder');

        //return Storage::disk('local')->directories("/");

        $data = $this->manager->folderInfo($folder);

        $login = auth()->user();

        /*
         * Base Folder?
         * */

        $ownedFolder = '';

        if (!is_null($login->staffId)) {
            $ownedFolder = AccessHeader::where('name',$login->staffs['position'])->first();
        } elseif (!is_null($login->pengurusId)) {
            $ownedFolder = AccessHeader::where('name',$login->pengurus['department'])->first();
        }

        $baseFolder = $ownedFolder['filePath'];                              // /Media/

        $baseFolder = substr($baseFolder, 0, strlen($baseFolder) - 1);          // /Media
        $ownedFolder = Str::is($baseFolder,$folder);
        $baseFolder = Str::is($baseFolder . '*',$folder);                    // 1

        /*
         * Others Folder?
         * */
        //return $data['folder'];

        $nowFolder = AccessHeader::where('filePath','like',$data['folder'].'%')->first();

        $sharedFolder = AccessDetail::where('accessId',$nowFolder['id'])->get();

        $baseSharedFolder = $othersFolder = $othersBaseFolder = '';

        if($sharedFolder->isEmpty()){
            $sharedFolder = AccessDetail::where('accessId',$nowFolder['parentAccessId'])->get();
            if(!$sharedFolder->isEmpty()){
                if($nowFolder['userId'] == $login->id && $nowFolder['parentAccessId'] == null) {
                    $othersFolder = 0;
                }else {
                    $othersFolder = 1;
                }
            }else{

                $othersFolder = 0;
                if($nowFolder['parentAccessId'] != null) {
                    $baseSharedFolder = 0;
                }else{
                    $baseSharedFolder = 1;
                }
            }
        }

        /**
         * If not empty
        */

        else{
            if($nowFolder['userId'] == $login->id && $nowFolder['parentAccessId'] == null){ //folderkita
                $othersFolder = 0;
                $baseSharedFolder = 1;
            }else{
                $othersFolder = 1;
            }
        }

        $accessh = '';

        $flag[0] = 2;
        $flag[1] = 2;
        $loginArray = '';

        if (!is_null($login->staffId)) {
            $loginArray[] = $login->staffs->position;
        }elseif(!is_null($login->pengurusId)){
            $loginArray[] = $login->pengurus->department;
        }

            $aheadsFolder = AccessHeader::select('filePath')
                ->where('userId', $login->id)
                ->where('type', 'folder')
                ->whereNotIn('name',$loginArray)
                ->get();

            $aheadsFile = AccessHeader::select('filePath')
                ->where('userId', $login->id)
                ->where('type', 'file')
                ->get();

        $shareTo = AccessHeader::where('filePath',$folder.'/');

        $sharedToSekretarisJenderal = $sharedToWakilSekretarisJenderal = $sharedToSekretaris = $sharedToFundraiser
        = $sharedToKeuangan = $sharedToLiteratur = $sharedToMedia = $sharedToUmum
        = $sharedToPengurusHarianNasional = $sharedToBadanPengurusNasional = $sharedToBadanPembina = $sharedToBadanPengawas =  0;

        if(!$shareTo->get()->isEmpty()) {
            if (!$shareTo->first()->accessDetails->where('shareTo','Badan Pembina')->isEmpty()){
                $sharedToBadanPembina = 1;
            };

            if (!$shareTo->first()->accessDetails->where('shareTo','Badan Pengawas')->isEmpty()){
                $sharedToBadanPengawas = 1;
            };

            if (!$shareTo->first()->accessDetails->where('shareTo','Pengurus Harian Nasional')->isEmpty()){
                $sharedToPengurusHarianNasional = 1;
            };

            if (!$shareTo->first()->accessDetails->where('shareTo','Badan Pengurus Nasional')->isEmpty()){
                $sharedToBadanPengurusNasional = 1;
            };

            if (!$shareTo->first()->accessDetails->where('shareTo','Wakil Sekretaris Jenderal')->isEmpty()){
                $sharedToWakilSekretarisJenderal = 1;
            }

            ;if (!$shareTo->first()->accessDetails->where('shareTo','Sekretaris Jenderal')->isEmpty()){
                $sharedToSekretarisJenderal = 1;
            };

            if (!$shareTo->first()->accessDetails->where('shareTo','Sekretaris')->isEmpty()){
                $sharedToSekretaris = 1;
            }

            if (!$shareTo->first()->accessDetails->where('shareTo','Keuangan')->isEmpty()){
                $sharedToKeuangan = 1;
            }

            if (!$shareTo->first()->accessDetails->where('shareTo','Fundraiser')->isEmpty()){
                $sharedToFundraiser = 1;
            }

            if (!$shareTo->first()->accessDetails->where('shareTo','Media')->isEmpty()){
                $sharedToMedia = 1;
            }

            if (!$shareTo->first()->accessDetails->where('shareTo','Umum')->isEmpty()){
                $sharedToUmum = 1;
            }

            if (!$shareTo->first()->accessDetails->where('shareTo','Literatur')->isEmpty()){
                $sharedToLiteratur = 1;
            }
        }

        return view('file.file_lists',$data,compact(
            'sharedToBadanPembina',
            'sharedToBadanPengawas',
            'sharedToPengurusHarianNasional',
            'sharedToBadanPengurusNasional',
            'sharedToSekretarisJenderal',
            'sharedToWakilSekretarisJenderal',
            'sharedToSekretaris',
            'sharedToKeuangan',
            'sharedToFundraiser',
            'sharedToUmum',
            'sharedToLiteratur',
            'sharedToMedia',
            'myFolder','login','aheadsFolder','aheadsFile','baseFolder','accessh','flag','othersFolder','baseSharedFolder'));
    }

file_lists.blade.php

  @include('file._modals')

_modals.blade.php

<input type="checkbox" name="role[]" id="role" value="Badan Pembina"
    @if($login->staffs['position'] == 'Badan Pembina')disabled checked
    @elseif($login->staffs['position'] != 'Badan Pembina' 
    && $sharedToBadanPembina == 1) checked
    @endif> Pengurus Harian Nasional<br>

<input type="checkbox" name="role[]" id="role" value="Badan Pengawas"
   @if($login->staffs['position'] == 'Badan Pengawas')disabled checked
   @elseif($login->staffs['position'] != 'Badan Pengawas'
   && $sharedToBadanPengawas == 1) checked
   @endif> Pengurus Harian Nasional<br>

<input type="checkbox" name="role[]" id="role" value="Pengurus Harian Nasional"
   @if($login->staffs['position'] == 'Pengurus Harian Nasional')disabled checked
   @elseif($login->staffs['position'] != 'Pengurus Harian Nasional'
   && $sharedToPengurusHarianNasional == 1) checked
   @endif> Pengurus Harian Nasional<br>

<input type="checkbox" name="role[]" id="role" value="Badan Pengurus Nasional"
   @if($login->staffs['position'] == 'Badan Pengurus Nasional')disabled checked
   @elseif($login->staffs['position'] != 'Badan Pengurus Nasional'
   && $sharedToBadanPengurusNasional == 1)checked
   @endif> Badan Pengurus Nasional<br>



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire