Laravel 5.4。
我想在用户尝试登录时设置会话。我发现我可以在LoginController.php中使用登录功能。
我的代码:
public function login(Request $request)
{
//Set session as 'login'
Session::put('last_auth', 'login');
}
它正确设置了我的会话,但它没有继续登录,我得到一个空白页面。
如何在设置会话后对我的功能说继续登录?
由于
答案 0 :(得分:2)
如果您想覆盖原始laravel默认登录功能,可以将其放入Auth\LoginController
,并记住导入use Illuminate\Http\Request;
public function login(Request $request)
{
// Here is your customized code
Session::put('last_auth', 'login');
$this->validateLogin($request);
// If the class is using the ThrottlesLogins trait, we can automatically throttle
// the login attempts for this application. We'll key this by the username and
// the IP address of the client making these requests into this application.
if ($this->hasTooManyLoginAttempts($request)) {
$this->fireLockoutEvent($request);
return $this->sendLockoutResponse($request);
}
if ($this->attemptLogin($request)) {
return $this->sendLoginResponse($request);
}
// If the login attempt was unsuccessful we will increment the number of attempts
// to login and redirect the user back to the login form. Of course, when this
// user surpasses their maximum number of attempts they will get locked out.
$this->incrementLoginAttempts($request);
return $this->sendFailedLoginResponse($request);
}
这里是寄存器功能
导入use Illuminate\Auth\Events\Registered;
并添加:
public function register(Request $request)
{
$this->validator($request->all())->validate();
event(new Registered($user = $this->create($request->all())));
$this->guard()->login($user);
return $this->registered($request, $user)
?: redirect($this->redirectPath());
}