Package Data | |
---|---|
Maintainer Username: | 5-say |
Maintainer Contact: | bcw.5@foxmail.com (FiveSay) |
Package Create Date: | 2014-08-12 |
Package Last Update: | 2014-09-29 |
Home Page: | |
Language: | PHP |
License: | Unknown |
Last Refreshed: | 2024-12-19 03:06:56 |
Package Statistics | |
---|---|
Total Downloads: | 435 |
Monthly Downloads: | 0 |
Daily Downloads: | 0 |
Total Stars: | 4 |
Total Watchers: | 3 |
Total Forks: | 2 |
Total Open Issues: | 0 |
对象化分组路由辅助工具
在 composer.json 文件中申明依赖:
"five-say/laravel-route-group": "1.*"
在 /app/config/app.php
中设置“服务提供者”与“别名”
'providers' => array(
...
'FiveSay\LaravelRouteGroup\ServiceProvider',
),
'aliases' => array(
...
'RouteGroup' => 'FiveSay\LaravelRouteGroup\Facade',
),
RouteGroup::make()->controller('AdminController')->go(function ($route) {
$route->get('/')->as('admin')->uses('getIndex');
});
想知道它为我们注册了什么路由?我们来加一个小尾巴
->dd()
就像下面这样:
RouteGroup::make()->controller('AdminController')->go(function ($route) {
$route->get('/')->as('admin')->uses('getIndex');
})->dd();
虽然对象化了,但总觉的代码量反而更多了是不是?没关系,让我们来个霸气点的:
RouteGroup::make('admin')->as('admin')->before('auth')
->controller('AdminController')->go(function ($route) {
$route->index( )
->create( )
->store( )
->edit( )
->update( )
->destroy();
})->dd();
现在有点感觉了?我们还可以做到更多:
RouteGroup::make('admin')->as('admin')->before('auth')
->controller('AdminController')->go(function ($route) {
$route->index( )
->create( )->beforeClear()
->store( )->before('more')->before('more2|more3')
->edit( )->beforeOnly('myself')
->update( );
$route->delete('{id}')->as('destroy')->uses('destroy');
})->dd();
哦,对了,这里还有个大尾巴
->ddAll()
它将输出在此之前,由此辅助注册的所有路由信息。
请参考此项目 5-say/laravel-4.1-simple-blog。