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!');
        }
    }

https://img.mukewang.com/5c8f6d5c000147ce08000625.jpg

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)
人到中年有点甜
浏览 895回答 4
4回答

MMMHUHU

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.

富国沪深

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

慕斯王

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

当年话下

好似是你的adduser 返回类型错误,,LoginController继承了trait AuthenticateUsers 其中的Login函数类型为Request的参数,但愿对你有帮助,
打开App,查看更多内容
随时随地看视频慕课网APP