Laravel手动登录功能 [英] Laravel manual login function
问题描述
我在Laravel 5.5中使用手动登录功能.卡住了登录.并检查所有(5个相关的)堆栈链接,但没有发现任何线索.
I use manual login function in Laravel 5.5. Stuck in login. and check all(5 relevant ) Stack links and didn't find any clue on it.
成就是在用户注册后自动登录该用户.
Achievement is once user get registered, automatically sign in that user.
错误是
Error is
类型错误:传递给Illuminate \ Auth \ SessionGuard :: login()的参数1必须实现接口Illuminate \ Contracts \ Auth \ Authenticatable,已给定字符串,在Server/vendor/laravel/framework/src/Illuminate/Auth中调用/AuthManager.php在第294行◀"
"Type error: Argument 1 passed to Illuminate\Auth\SessionGuard::login() must implement interface Illuminate\Contracts\Auth\Authenticatable, string given, called in Server/vendor/laravel/framework/src/Illuminate/Auth/AuthManager.php on line 294 ◀"
if ($validator->fails()) {
// $messages = $validator->messages();
return Redirect::to('register')
->withErrors($validator)
->withInput();
} else {
$email = Input::get('email');
$user = new user;
$user->name = Input::get('name');
$user->email = Input::get('email');
$user->password = Hash::make(Input::get('password'));
$user->save();
// $userMail = $user->find($email);
$userMail = User::where('email','=',$email)->first();
Auth::login($userMail->email, TRUE);
我做错了什么.请指导我.
am i doing anything wrong. Please guide me.
推荐答案
登录功能需要类型为Authenticatable
的用户,而您刚刚给出了email
,这是字符串,这就是为什么会出现此错误的原因,请使用Auth::loginUsingId($id);
>
Login function needs user of type Authenticatable
and you just given email
which is string thats why you get this error, Either use Auth::loginUsingId($id);
$user = User::where('email','=',$email)->first();
Auth::loginUsingId($user->id, TRUE);
或者只是
Auth::login($user);
这篇关于Laravel手动登录功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!