打扰各位一下,我在使用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 回答
![?](http://img1.sycdn.imooc.com/54584ed2000152a202200220-100-100.jpg)
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.
![?](http://img1.sycdn.imooc.com/545863c10001865402200220-100-100.jpg)
富国沪深
TA贡献1790条经验 获得超9个赞
$user = (new Users())->addUser($data);
这个返回的是什么?
你的Users
类有没有继承Illuminate\Foundation\Auth\User
?
![?](http://img1.sycdn.imooc.com/545868190001d52602200220-100-100.jpg)
当年话下
TA贡献1890条经验 获得超9个赞
好似是你的adduser 返回类型错误,,LoginController继承了trait AuthenticateUsers 其中的Login函数类型为Request的参数,但愿对你有帮助,
- 4 回答
- 0 关注
- 894 浏览
添加回答
举报
0/150
提交
取消