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

Laravel5.4 认证机制中的注册跳转时出现了问题

Laravel5.4 认证机制中的注册跳转时出现了问题

PHP
人到中年有点甜 2019-03-18 18:05:20
打扰各位一下,我在使用Auth认证的时候RegisterController在跳转时出现异常(创建用户是成功的)。万分感谢!! RegisterController create user code Register class RegisterController extends Controller /** * Create a new user instance after a valid registration. * @param array $data * @return \Illuminate\Http\RedirectResponse|string */ protected function create(array $data) { $user = (new Users())->addUser($data); if($user){ Auth::guard()->login($user); return $this->redirectTo; }else{ return redirect()->back() ->with('status','An unknown error occurred!please try again!'); } } Exception Description at HandleExceptions->handleError(4096, 'Argument 1 passed to Illuminate\\Auth\\SessionGuard::login() must implement interface Illuminate\\Contracts\\Auth\\Authenticatable, string given, called in D:\\PHPSpace\\brookblog\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Auth\\RegistersUsers.php on line 35 and defined', 'D:\\PHPSpace\\brookblog\\vendor\\laravel\\framework\\src\\Illuminate\\Auth\\SessionGuard.php', 408, array()) in SessionGuard.php (line 408)
查看完整描述

4 回答

?
MMMHUHU

TA贡献1834条经验 获得超8个赞

Sometimes programming is so interesting.

This problem has been bothering me all day.

When I was about to get off work, the problem was solved.

But I can't tell the reason for the problem myself.

    /**
     * Create a new user instance after a valid registration.
     * @param Request $request
     * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
     */
    public function register(Request $request)
    {
        $user = (new Users())->addUser($request->all());
        event(new Registered($user));
        $this->guard()->login($user);
        return $this->registered($request, $user)
                    ?: redirect($this->redirectPath());
    }

If you have the same problem, I hope my experience can be of some help.

查看完整回答
反对 回复 2019-03-18
?
富国沪深

TA贡献1790条经验 获得超9个赞

$user = (new Users())->addUser($data);这个返回的是什么?
你的Users类有没有继承Illuminate\Foundation\Auth\User

查看完整回答
反对 回复 2019-03-18
?
慕斯王

TA贡献1864条经验 获得超2个赞

看红框, 那儿应该是一个user对象.

https://img1.sycdn.imooc.com//5c8f6d5f00013ecf08000470.jpg

查看完整回答
反对 回复 2019-03-18
?
当年话下

TA贡献1890条经验 获得超9个赞

好似是你的adduser 返回类型错误,,LoginController继承了trait AuthenticateUsers 其中的Login函数类型为Request的参数,但愿对你有帮助,

查看完整回答
反对 回复 2019-03-18
  • 4 回答
  • 0 关注
  • 894 浏览

添加回答

举报

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