gpt4 book ai didi

php - 在 Laravel 5 上手动登录用户

转载 作者:搜寻专家 更新时间:2023-10-31 20:38:00 24 4
gpt4 key购买 nike

我正在使用 facebook JS 将用户登录到 laravel 5 应用程序。我能够正确地将信息添加到数据库中,但我正在尝试手动登录用户,但无法弄清楚。

这是我的 Controller :

    <?php namespace App\Http\Controllers;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Http\lib\TopAdditions;
use App\Http\lib\GeneralFunctions;
use App\User;

class FacebookLoginController extends Controller{
public function FacebookRegistration(){


$facebook = new User();
$isThereAUser = User::where('name', $_GET['name'])->get();

if(!count($isThereAUser) > 0){
$facebook->name = $_GET['name'];
$facebook->email = $_GET['email'];
$facebook->password = sha1($_GET['password']);
$facebook->remember_token = $_GET['token'];
$facebook->save();

$id = User::where('name', $_GET['name'])->get();
$this->LoginUser($id);

}

}

public function LoginUser($id){

\Auth::login($id[0]['id'],true);



}
}

当我运行它并且数据库中没有这样的用户时,该用户被创建并且在尝试手动登录时我收到此消息:

ErrorException in Guard.php line 425: Argument 1 passed to Illuminate\Auth\Guard::login() must implement interface Illuminate\Contracts\Auth\Authenticatable, integer given

我一直在网上搜索类似的情况,但找不到任何有帮助的...

请帮帮我!

最佳答案

您应该将用户对象而不是 ID 传递给 Auth::login。所以只需将您的功能更改为这样:

public function LoginUser($user){
\Auth::login($user, true);
}

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

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