2014-12-03 113 views

回答

1

你運用它在構造

class NewsController extends Controller { 


    public function __construct() 
    { 
     $this->middleware('user', ['only' => 'create']); 
    } 


    public function create() 
    { 
     // do stuff here 
    } 
+1

如果我想多方法用什麼相同的中間件? – Kevin 2015-03-09 22:44:58

+0

這對我來說第一次嘗試 - 非常令我驚訝: $ this-> middleware('auth',['only'=> array('create','index')]); – Peter 2015-03-20 08:21:55

+0

您也可以將它應用到您的路線中,例如:http://laravel.io/forum/02-17-2015-laravel-5-routes-restricting-based-on-user-type – 2015-04-22 10:06:32