Laravel Group Admin Routes

Is there a way to clear all routes starting with admin/ ? I tried something like this, but this did not work:

 Route::group('admin', function() { Route::get('something', array('uses' => ' mycontroller@index ')); Route::get('another', array('uses' => ' mycontroller@second ')); Route::get('foo', array('uses' => ' mycontroller@bar ')); }); 

According to these routes:

 admin/something admin/another admin/foo 

I can, of course, just prefix all these routes directly with admin/ , but I would like to know if this is possible in my opinion.

Thanks!

+4
source share
2 answers

Unfortunately not. Route groups were not designed to do this. This is taken from Laravel docs.

Route groups allow you to attach a set of attributes to a route group, which allows you to keep your code neat and tidy.

A route group is used to apply one or more filters to a route group. What you are looking for are packages!

Getting to know the packages!

Ligaments are what you need in the appearance of things. Create a new package called "admin" in your packages directory and register it in the application / bundles.php file, something like this:

 'admin' => array( 'handles' => 'admin' ) 

The handle key allows you to change which URI the packet will respond to. Thus, in this case, admin calls will be made through this package. Then in your new package create a route.php file and you can register the handler using (: bundle) .

 // Inside your bundles routes.php file. Route::get('(:bundle)', function() { return 'This is the admin home page.'; }); Route::get('(:bundle)/users', function() { return 'This responds to yoursite.com/admin/users'; }); 

Hope you get some ideas.

+3
source

In Laravel 4 you can now use prefix :

 Route::group(['prefix' => 'admin'], function() { Route::get('something', ' mycontroller@index '); Route::get('another', function() { return 'Another routing'; }); Route::get('foo', function() { return Response::make('BARRRRR', 200); }); Route::get('bazz', function() { return View::make('bazztemplate'); }); }); 
+3
source

Source: https://habr.com/ru/post/1434867/


All Articles