gpt4 book ai didi

php - Laravel 手动登录功能

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:51:49 25 4
gpt4 key购买 nike

我在 Laravel 5.5 中使用手动登录功能。卡在登录中。并检查所有(5 个相关)堆栈链接,但没有找到任何线索。

Achievement is once user get registered, automatically sign in that user.


错误是

"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);

我做错了什么吗?请指导我。

最佳答案

登录函数需要类型为 Authenticatable 的用户,而您刚刚给定了 email 字符串,这就是您收到此错误的原因,要么使用 Auth::loginUsingId($ id);

 $user = User::where('email','=',$email)->first();
Auth::loginUsingId($user->id, TRUE);

或者只是

Auth::login($user);

关于php - Laravel 手动登录功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46362505/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com