我已经使用make:auth命令创建了身份验证系统,并且它一直运行良好
我创建了另一个Restful控制器,我一直在routes.php上使用Route :: controller
就像这段代码一样,请阅读代码中的//注释
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
});
我看到隐式路由与中间件无法正常工作,但我不知道相应的解决方案
答案 0 :(得分:2)
您实际上需要auth
中间件而非网络进行身份验证:
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');
}
...
...
}
答案 1 :(得分:0)
谢谢可以,解决方案是在控制器文件中添加此代码
class accountController extends Controller
{
/**
* Instantiate a new accountController instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('auth');
}
...
...
}