Reputation: 483
I have some routes in routes.php in laravel
// Code for rounting admin panel
Route::resource('/admin','Admin\LoginController@index');
Route::resource('/admin/dashboard','Admin\AdminController@index');
Route::resource('/admin/movies','Admin\MovieController@index');
Now when I access url http://localhost/askspidy/admin I want to show login page and it works, but when i access url http://localhost/askspidy/admin/dashboard it should go to dashboard but it's showing me login page only. I know this is because when it found /admin in any url it's bydefault goes to the route
Route::resource('/admin','Admin\LoginController@index');
I know it's assuming that (/admin) is route to controller and (/dashboard) is the function declared in the controller but I want routing like this only so is there any other solution for this problem.
Upvotes: 0
Views: 696
Reputation: 13667
A RESTful Resource Controller takes over the responsibility of each action. You only need to list the name and the controller:
Route::resource('photo', 'PhotoController');
If you wanted to only use the index
method, you’d list it like this:
Route::resource('photo', 'PhotoController', ['only' => [
'index'
]]);
However, it looks like two of your routes are not suitable for resources (login and dashboard), as they should relate to editing a model.
You should instead just use a get()
resource instead.
Route::get('user/{id}', 'UserController@showProfile');
So in your case, it would be:
Route::get('/admin','Admin\LoginController@index');
Route::get('/admin/dashboard','Admin\AdminController@index');
Route::resource('/admin/movie','Admin\MovieController');
Upvotes: 1