控制器中介軟體
可以將中介軟體分配給路徑檔案中的控制器路徑:
Route::get('profile', 'UserController@show')->middleware('auth');
但是,在控制器的建構函式中指定中介軟體更方便。使用控制器建構函式中的中介軟體方法,你可以輕鬆地將中介軟體分配給控制器的操作。
class UserController extends Controller
{
    /**
     * Instantiate a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('auth');
        $this->middleware('log')->only('index');
        $this->middleware('subscribed')->except('store');
    }
}