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

查看:193
本文介绍了php - Laravel5.4 认证机制中的注册跳转时出现了问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问 题

打扰各位一下,我在使用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)

解决方案

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.

这篇关于php - Laravel5.4 认证机制中的注册跳转时出现了问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆