This is my routes :
I have Route Name Prefixes (admin) with namespace (Admin) for controller and prefix for url (users) , the code below works correctly but i want to use resource :
Route::prefix('users')->name('admin.')->namespace('Admin')->middleware(['auth'])->group(function () {
Route::get('', 'UsersController@index')->name('users.index');
Route::get('/create', 'UsersController@create')->name('users.create');
Route::post('/create', 'UsersController@store');//->name('admin.users.store');
Route::get('/edit/{user_id}', 'UsersController@edit')->name('users.edit');
Route::post('/edit/{user_id}', 'UsersController@update');//->name('admin.users.edit');
Route::get('/delete/{user_id}', 'UsersController@destroy')->name('users.delete');
});
when i use the code below and open the urls like :
site.com/users/create and other urls ... it show me 404
Not Found Page!
Route::prefix('users')->name('admin.')->namespace('Admin')->middleware(['auth'])->group(function () {
Route::resource('users', 'UserController');
});
Why is this is happening? ? how can i use resource like the first code that works?
php artisan route:list
– KingoClass App\Http\Controllers\Admin\UserController does not exist
My Class names have s like UsersController , should i rename my controllers in Singular form? all of my controllers name are plural – Amin ArjmandUserController
and changenamespace
toApp\Http\Controllers\Admin;
– Kingo