我已经使用了make:auth命令来创建身份验证系统,并且它一直工作正常
我创建了另一个 Restful 控制器,并且我一直在路由上使用 Route::controller.php
像这个代码,请阅读代码中的//注释
Route::group(['prefix' => 'dashboard', 'middleware' => 'web'], function () {
Route::auth();
Route::get('/', 'HomeController@index'); // working fine and requires logging in
Route::get('test', 'HomeController@index'); // working fine and requires logging in
Route::controller('account','accountController'); // doesn't work and I can visit this page without logging in
});
我看到隐式路由在中间件上无法正常工作,但我不知道合适的解决方案
您实际上需要auth
中间件而不是 Web 进行身份验证:
Route::get('profile', ['prefix' => 'dashboard', 'middleware' => 'auth'], function() {
Route::controller('account','accountController');
}]);
另一种选择是在控制器中设置此设置。
class accountController extends Controller
{
/**
* Instantiate a new accountController instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('auth');
}
...
...
}
谢谢可以, 解决方案是在控制器文件中添加此代码
class accountController extends Controller
{
/**
* Instantiate a new accountController instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('auth');
}
...
...
}