我正在尝试根据Laravel 5.3中的API对用户进行身份验证 . 它不起作用 . 用户在登录后重定向后,Auth不会保留 .
路由配置如下:
Route::group(['middleware' => 'web'], function () {
Route::group(['middleware' => 'auth'], function () {
Route::get('/', 'Users\DashboardController@index');
});
// Authentication routes...
Route::get('login', 'Auth\LoginController@getLogin');
Route::post('login', 'Auth\LoginController@postLogin');
Route::get('logout', 'Auth\LoginController@getLogout');
});
在LoginController.php我正在使用
protected $redirectTo = '/';
public function getLogin()
{
return view('auth.login');
}
public function postLogin(Request $request)
{
$this->login($request);
}
登录成功保存在文件中后,路径 '/'
的会话未启动 .
所以 'login'
路线:
dd($session);
在Illuminate \ Auth \ SessionGuard中返回 #started : true
Store {#153 ▼
#id: "fo9Q8WuBio5BBus70WmzFPZmkXkjsYQlYEHsVHI4"
#name: "laravel_session"
#attributes: array:4 [▼]
#bags: []
#metaBag: MetadataBag {#144 ▼}
#bagData: array:1 [▼]
#handler: FileSessionHandler {#154 ▼}
#started: true
}
但当路由在 'auth'
中间件组(在我的情况下为 '/'
)时 #started
为false .
我检查了一些,当我把 '/'
路由放在 'auth'
中间件组外但在控制器中调用 Auth::check()
时, #started
也是假的 .
这个问题似乎已经存在于5.2(Auth not persisting in Laravel 5.2)中,但那里的解决方案并不适用于我 .
请帮助我理解登录后无法访问 '/'
路线的原因 . 谢谢!
1 回答
改变kernel.php'api'
至