传递给Illuminate \ Auth \ Guard :: login()的参数1必须实现接口Illuminate \ Auth \ UserInterface,如果打开则为null: [英] Argument 1 passed to Illuminate\Auth\Guard::login() must implement interface Illuminate\Auth\UserInterface, null given open:

查看:107
本文介绍了传递给Illuminate \ Auth \ Guard :: login()的参数1必须实现接口Illuminate \ Auth \ UserInterface,如果打开则为null:的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用OAuth2执行Facebook登录,然后使用Laravel 4的内置身份验证系统在重新访问时重新登录用户.对于大多数用户,我发现我的财产没有问题,但是对于一个用户,他看到登录时出现以下错误:

I have a Facebook login I am performing with OAuth2, and then I am using Laravel 4's built in Authentication system to log the user back in on revisit. For the majority of users, I see no issues with what I have, but for one user, he is seeing the following error appear on login:

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

这是控制器中的相关登录/身份验证代码:

Here is the relevant login/authentication code in the 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);

               }

这是我在用于保存用户信息的表的模型中的代码,称为粉丝":

This is my code in the model for the table I am using to keep user information, called "Fans":

<?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; 
}

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

This is very perplexing because this login works for all of the other profiles I have tried. It is only with this friend's profile that it is throwing this error. I will also add, that on login (or retries) it will create multiple entries for this user in the database/table. This authentication system is supposed to be set up to prevent exactly this. Is there anything I'm missing?

推荐答案

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

in the create() method in the LoginController you must return the $user that worked for me

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

        return $user;
    }

这篇关于传递给Illuminate \ Auth \ Guard :: login()的参数1必须实现接口Illuminate \ Auth \ UserInterface,如果打开则为null:的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆