gpt4 book ai didi

authentication - 传递给 Illuminate\Auth\Guard::login() 的参数 1 必须实现接口(interface) Illuminate\Auth\UserInterface,null 给定打开:

转载 作者:行者123 更新时间:2023-12-04 03:27:54 25 4
gpt4 key购买 nike

我有一个使用 OAuth2 执行的 Facebook 登录,然后我使用 Laravel 4 的内置身份验证系统在重新访问时重新登录用户。对于大多数用户,我认为我所拥有的没有任何问题,但对于一位用户,他看到登录时出现以下错误:

ErrorException
Argument 1 passed to Illuminate\Auth\Guard::login() must implement interface Illuminate\Auth\UserInterface, null given
open: */nfs/c09/h04/mnt/139243/domains/crowdsets.com/vendor/laravel/framework/src/Illuminate/Auth/Guard.php
* /**
* Log a user into the application.
*
* @param \Illuminate\Auth\UserInterface $user
* @param bool $remember
* @return void
*/
public function login(UserInterface $user, $remember = false)
{
$id = $user->getAuthIdentifier();

这是 Controller 中的相关登录/身份验证代码:
$check = Fan::where('fbid', '=', $user['uid'])->first();

if(is_null($check)) {

$fan = new Fan;

$fan->fbid = $user['uid'];
$fan->email = $user['email'];
$fan->first_name = $user['first_name'];
$fan->last_name = $user['last_name'];
$fan->gender = $user['gender'];
$fan->birthday = $user['birthday'];
$fan->age = $age;
$fan->city = $city;
$fan->state = $state_abbrev;
$fan->image = $user['image'];
$fan->friend_ids_url = $user['friends'];
$fan->friend_ids_unpacked = $friend_ids;

$fan->save();

$new = Fan::where('fbid', '=', $user['uid'])->first();

Auth::login($new);
return Redirect::to('fans/home');

}

else {

Auth::login($check);

$fan = Fan::find(Auth::user()->id);
$fan->image = $user['image'];
$fan->save();

return Redirect::to('fans/home');
var_dump($user);

}

这是我用来保存用户信息的表的模型中的代码,称为“粉丝”:
<?php

use Illuminate\Auth\UserInterface;

class Fan extends Eloquent implements UserInterface {
protected $guarded = array();

public static $rules = array();

public function getAuthIdentifier()
{
return $this->getKey();
}


public function getAuthPassword()
{
return $this->password;
}

这非常令人困惑,因为此登录名适用于我尝试过的所有其他配置文件。只有这个 friend 的个人资料才会抛出这个错误。我还要补充一点,在登录(或重试)时,它将在数据库/表中为此用户创建多个条目。应该设置此身份验证系统以防止这种情况发生。有什么我想念的吗?

最佳答案

在 LoginController 的 create() 方法中,您必须返回 $user
对我有用

protected function create(array $data)
{
$user = User::create([
'username' => $data['username'],
'email' => $data['email'],
'password' => bcrypt($data['password']),
]);

return $user;
}

关于authentication - 传递给 Illuminate\Auth\Guard::login() 的参数 1 必须实现接口(interface) Illuminate\Auth\UserInterface,null 给定打开:,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19039870/

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