为了账号安全,请及时绑定邮箱和手机立即绑定

如何在 Laravel 中为自定义注册表单设置自定义自动登录

如何在 Laravel 中为自定义注册表单设置自定义自动登录

PHP
茅侃侃 2022-07-22 19:01:34
这是 laravel 中的用户注册自定义表单。public function register(RegisterTalentRequest $request) {    $talent = $this->create($request->except('_method', '_token'));    //up till here the registration values are successfully saved in the     //database table, but it's not logged in following the below code    //and is directing to the custom login page.    Auth::attempt(['email' => $request->email, 'password' => $request->password]);    return redirect()->route('dashboard'); //directing to login and not dashboard}
查看完整描述

2 回答

?
慕田峪9158850

TA贡献1794条经验 获得超7个赞

默认情况下,Auth外观(或auth()辅助函数)将使用文件guard中的默认设置config/auth.php

如果您想在登录或注册方法中使用不同的保护,您需要显式设置它:

Auth::guard('guard-name')->attempt(...);

或者,当使用authorguest中间件时,您可以传递您想要使用的保护,例如 (auth:guard-nameguest:guard-name) 这会将默认保护设置guard-name为请求的其余部分,因此您不需要显式设置它。


查看完整回答
反对 回复 2022-07-22
?
牧羊人nacy

TA贡献1862条经验 获得超7个赞

我假设在您注册时它返回了一个用户。那么你可以使用这个

Auth::login($user);


查看完整回答
反对 回复 2022-07-22
  • 2 回答
  • 0 关注
  • 116 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信