我想在我的控制器中使用中间件,但我事先并不知道路由,因为我从我的数据库中取出了slug。
在laravel 5中有可能吗?
提前谢谢
答案 0 :(得分:4)
在控制器的构造函数中,执行以下操作:
public function __construct()
{
//This will apply to every method inside the controller
$this->middleware('auth');
//This will apply only to the methods listed inside the array
$this->middleware('log', ['only' => ['fooAction', 'barAction']]);
//This will apply only to the methods except the ones listed inside the array
$this->middleware('subscribed', ['except' => ['fooAction', 'barAction']]);
}
您可以阅读here