1

I have a route group under a prefix admin:

Route::group(['prefix' => 'admin'], function(){
    Route::get('/', 'AdminController@method');
});

I would like a url such as /admin/dashboard/ and /admin/blogmanager/, basically, any arbitrary url under the admin prefix to be mapped to the same controller method without listing each url one by one. I would like a url pattern to accept all urls as long as it is prefixed by admin

TaeKwonDev
  • 93
  • 1
  • 8

3 Answers3

1

You could do that with Route::controller() method but it was removed from Laravel and I think it's for good, because all routes should be explicit.

You can use Route::resource() fro CRUD controllers.

Alexey Mezenin
  • 158,981
  • 26
  • 290
  • 279
0

You can use {any} syntax:

Route::group(['prefix' => 'admin'], function(){
    Route::get('{any}', 'AdminController@handle');
});

Every route with prefix admin will be handled by AdminController.

If you want urls like: /admin/profile/post,... use:

Route::get('{any}', 'AdminController@handle')->where('any', '.*');
Mako
  • 242
  • 2
  • 6
0

You can use this:

Route::group(['prefix' => 'admin'], function(){
     Route::get('{any_url?}', 'AdminController@method');
});

With this all route with prefix admin will be handled by AdminController. And your AdminController should look like this.

Class AdminController extends Controller{

      public function method($any_url = NULL){
         //Put some conditions here
      }
}