0
votes

I build a backend for admin in my application and create a route group for admin with a middleware Admin.

I place all my route resource for edit create delete in this group but when I try to navigate in this route with my nav menu

<a href="{{ action('CategorieController@index') }}">

I have an error for routing collection URL generator.

why I can't use the resource in a group with a prefix? That's my code with route resource (not working)

    Route::group(['prefix' => 'admin' ,'middleware' => 'admin'], function() {

    Route::resource('categories','CategorieController');

});

But that's work perfectly

Route::group(['prefix' => 'admin' ,'middleware' => 'admin'], function() {     
Route::get('categories/allcat',['as'=>'categories.index','uses'=>'CategorieController@index']);
    Route::get('categories/ajout',['as'=>'categories.create','uses'=>'CategorieController@create']);
    Route::post('categories/ajout',['as'=>'categories.store','uses'=>'CategorieController@store']);
    Route::get('categories/editer/{id}',['as'=>'categories.edit','uses'=>'CategorieController@edit']);
    Route::patch('categories/editer/{id}',['as'=>'categories.update','uses'=>'CategorieController@update']);
    Route::delete('categories/destroy/{id}',['as'=>'categories.destroy','uses'=>'CategorieController@destroy']);
});

Just need a little help for understand why resource route does not work in a group with a prefix.

1

1 Answers

1
votes

It doesn't work because you are using custom methods instead of Laravel's.

Try to keep original methods :

Route::get('categories/create'), ....

instead of :

Route::get('categories/ajout'), ....