2015-05-25 88 views

回答

1

我試圖做它和它的作品對我非常好: 在我的路線文件:

Route::group(['prefix' => 'agenda', 'middleware' => 'auth', 'permissions' => 'user.create|user.delete'], function() { 
    //my routes here... 
}); 

和中間件裏面:

class AuthMiddleware { 
    private $r; 
    private $guard; 
    public function __construct(Router $r, Guard $g) 
    { 
     $this->r = $r; 
     $this->guard = $g; 
    } 

    /** 
    * Handle an incoming request. 
    * 
    * @param \Illuminate\Http\Request $request 
    * @param \Closure $next 
    * @return mixed 
    */ 
    public function handle($request, Closure $next) 
    { 
     $route = $this->r->getCurrentRoute(); 
     $action = $route->getAction(); //$action['permissions'] is the string received from the routes file. 
    } 
+3

請注意,即將發佈的Laravel 5.1包含中間件參數:http://laravel.com/docs/master/middleware#middleware-parameters – lukasgeiter

相關問題