0
votes

Trying to keep my Laravel project organized here, while letting it grow.

Currently I use:

Route::controller('/admin', 'AdminController');

...in order to allow the controller to service general admin pages. This is working fine, however I'd like to delegate specific subqueries to other controllers for cleanliness reasons.

For example, I'd like /admin/dashboard to resolve to AdminController@getDashboard. I'd also like /admin/gallery/ to resolve to AdminGalleryController@getIndex, and /admin/foo/bar to resolve to AdminFooController@getBar.

Is there a simple way to slowly expand functionality like this?


We've migrated to Laravel 5 and 5.1, and this still remains a good way to do things. If you aren't using route groups in Laravel, then you aren't doing Laravel right.

2

2 Answers

2
votes

You can define those others as controller routes as well. Just do it before Route::controller('admin') because Laravel searches the registered routes in the other you define them. Since /admin/gallery would match Route::controller('admin') as well as Route::controller('admin/gallery') latter has to be defined first:

Route::controller('admin/gallery', 'AdminGalleryController');
Route::controller('admin/foo', 'AdminFooController');
Route::controller('admin', 'AdminController');

Instead of writing admin every time a route group might be a nice improvement as well:

Route::group(['prefix' => 'admin'], function(){
    Route::controller('gallery', 'AdminGalleryController');
    Route::controller('foo', 'AdminFooController');
    Route::controller('/', 'AdminController');
});
1
votes

Yes. Simply declare your "exception" routes before your main controller route.

Route::get('/admin/gallery','AdminGalleryContoller@getIndex');
Route::get('/admin/dashboard','AdminController@getDasboard');
Route::controller('/admin','AdminController');