mercredi 27 mars 2019

Laravel web routing order

I am creating a storage app with laravel, and I'm working on the pages displaying the files. In my controller, there is one function to load files where deleted="no" to the home page, and another function to load files that where deleted="yes" to the bin page. However, the bin page refuses to load

Auth::routes(['verify' => true]);

Route::group(['middleware' => ['auth']], function(){
Route::get('get/{files}', 'RoofController@getFile')->name('getfile');
Route::name('roofs_path')->get('/home', 'RoofController@index');
Route::name('store_roof_path')->post('/home', 'RoofController@store');
Route::name('deletefile')->get('{fileToDelete}', 'RoofController@deleteFile');
});

//route to files not deleted
Route::name('index')->get('/home', 'RoofController@index')->middleware('verified');
//route to files deleted
Route::name('bin')->get('/home', 'RoofController@bin')->middleware('verified');

And the bin function in the controller

   public function index()
    {   
        //get id and name of user
        $id = Auth::id();
        //specify 'where' array...get only non-deleted files and user's files
        $files_to_get = ['user_id' => $id, 'deleted' => 'no'];

        //get all files into an array
        $all_files = File::where($files_to_get)->orderBy('created_at', 'DESC')->get();

    //print_r($all_files);

    return view('home', [
        'files' => $all_files
    ]);


}

public function bin()
{   
    //get id and name of user
    $id = Auth::id();
    //specify 'where' array...get only non-deleted files and user's files
    $files_to_get = ['user_id' => $id, 'deleted' => 'yes'];

    //get all files into an array
    $all_files = File::where($files_to_get)->orderBy('created_at', 'DESC')->get();

    //print_r($all_files);

    return view('bin', [
        'files' => $all_files
    ]);


}



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire