我是基于Laravel 5.1开发系统的。我有一个路由资源:
Route::resource('applicant', 'ApplicantController');
因此,我们期望控制器具有以下功能:
index, create, store, edit, update, delete
我想要的是仅在index
函数中应用中间件auth。通常,如果您想在整个控制器上应用Auth,则需要执行以下操作:
public function __construct()
{
$this->middleware('auth');
}
但是当我将其移除并只执行以下操作时:
public function index()
{
$this->middleware('auth');
return view('applicant.index');
}
它不起作用。我以前做过,很好用。
这是在我的 ApplicantController
中,我希望 create
函数是公开的,并且仅在 index
上应用登录验证。我将不使用 edit,update,delete
。