我有这段代码:
public function postLogin(Request $request) {
if(Auth::attempt(['username' => $request->username, 'password' => $request->password]))
{
return redirect()->intended('users/dashboards');
}else{
return redirect('/')->withInput()->with('message', 'Login Failed');
}
}
这是我的控制器:
Route::get('/', ['as' => 'home', 'uses' => 'HomeController@Home']);
Route::post('post-login', ['as' => 'post_login', 'uses' => 'HomeController@postLogin']);
Route::group(['middleware' => 'auth', 'prefix' => 'user'], function(){
Route::get('dashboards', ['as' => 'dashboards', 'uses' => 'HomeController@getDashBoards']);
});
我不知道为什么它总是返回假。我正在测试用户是否经过身份验证。如果我使用Auth::check()
,则返回false
,但如果我使用Auth::guests
则会返回true
。我对中间件感到困惑。有人可以帮帮我吗?
答案 0 :(得分:0)
实际上,错误发生在framework/src/Illuminate/Auth/Guard.php
protected function hasValidCredentials($user, $credentials) {
return ! is_null($user) && $this->provider->validateCredentials($user, $credentials);
}
所以只需用
替换return语句return ! is_null($user) ||
$this->provider->validateCredentials($user, $credentials);