Laravel 5 Route::group More Than One Controller Issue
I'm new to Laravel. I have url like this example.com/admin
, everything works fine with this. But when i want to make a route in admin like this example.com/admin/users
then i have a problem. My routes looks like this:
Route::group(['namespace' => 'Admin'], function() {
Route::resource('admin', 'AdminController');
Route::resource('admin/users', 'UsersController');
});
So i generated controllers via artisan command tool, and if i try to load ../admin/create
it works, but if i try to load .../admin/users
it show a blank page, but the strangest part is that .../admin/users/create
works.
I'm new to Laravel so maybe my understanding about routes is wrong and i cant do like i'm trying to do. Thanks in advance.
Answer
Laravel routing works like greedy match. In your route file if you have two routes like this
Route::group(['namespace' => 'Admin'], function() {
Route::resource('admin', 'AdminController');
Route::resource('admin/users', 'UsersController');
});
Laravel router for urls like admin/users
it will match against admin
route.
So a good tip for Laravel routing would be you create route in descending order.
The url has most backslashes value
you write that at top of you route file & then to less.
Route::group(['namespace' => 'Admin'], function() {
Route::resource('admin/users/**/**', '**');
Route::resource('admin/users/****', '***');
Route::resource('admin/users', 'UsersController');
Route::resource('admin', 'AdminController');
});
So here you solution will be, put your second route up & first one down
Route::group(['namespace' => 'Admin'], function() {
Route::resource('admin/users', 'UsersController');
Route::resource('admin', 'AdminController');
});
Related Questions
- → "failed to open stream" error when executing "migrate:make"
- → October CMS Plugin Routes.php not registering
- → OctoberCMS Migrate Table
- → OctoberCMS Rain User plugin not working or redirecting
- → October CMS Custom Mail Layout
- → October CMS - How to correctly route
- → October CMS create a multi select Form field
- → October CMS - Conditionally Load a Different Page
- → How to disable assets combining on development in OctoberCMS
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → OctoberCms component: How to display all ID(items) instead of sorting only one ID?
- → In OctoberCMS how do you find the hint path?
- → How to register middlewares in OctoberCMS plugin?