【问题标题】:Laravel Socialite Package ErrorLaravel 社交名媛包错误
【发布时间】:2018-12-20 21:26:51
【问题描述】:

我在尝试使用 google 或 Facebook 登录时遇到以下错误。

传递给 Illuminate\Auth\Guard::login() 的参数 1 必须实现 interface Illuminate\Contracts\Auth\Authenticatable, null given

我正在为 laravel 使用社交名流包。什么问题,我无法解决。我是第一次使用 laravel Socialite 包

use App\User;

use App\Http\Controllers\Controller;

use Illuminate\Auth\Events\Registered;

use Illuminate\Http\Request;

use Illuminate\Support\Facades\Validator;

use Illuminate\Foundation\Auth\RegistersUsers;

use Laravel\Socialite\Facades\Socialite;


class RegisterController extends Controller




{





protected function create(array $data)

    {
        return User::create([

            'name' => $data['name'],

            'email' => $data['email'],

            'password' => bcrypt($data['password']),

            'user_type' => 'user',

            'active_status' => '1'
        ]);
    }

    public function redirectToProvider()


    {

        return  Socialite::driver('facebook')->redirect();


    }

 public function handleProviderCallback()

    {



try{


$socialuser = Socialite::driver('facebook')->stateless()->user();



}  

catch(exception $e){


return redirect('/');

}

$user=User::where('facebook_id',$socialuser->getid())->first();

if(!$user)

User::create([

'facebook_id'=>$socialuser->getid(),

'email'=>$socialuser->getemail(),

'name'=>$socialuser->getname(),
    ]);

auth()->login($user);

    return redirect()->to('/dashboard');
    }
}

请帮助我。我是初学者。 谢谢

【问题讨论】:

  • 请更具体地说明您要执行的操作。你能提供一些代码吗?

标签: php laravel laravel-socialite


【解决方案1】:

检查您的用户模型,确保它实现了 Authenticable。我猜它目前扩展了 Model 但不使用 Authenticable。把它贴在这里让使用确认它看起来没问题。

【讨论】:

  • 我的用户模型已经实现了 Authenticable 但出现了错误
  • 再次查看您的代码。当您创建新用户时,您没有将其分配给变量。因此 $user 仍然为空。尝试 $user = User:create([....
  • 感谢它工作正常,但谷歌登录的这段代码出现同样的错误
  • 谷歌登录用哪个代码?我在问题代码中没有看到任何提及 Google 登录?
  • 我想在评论中添加谷歌登录代码,这可能与否
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-10-18
  • 2017-09-16
  • 1970-01-01
  • 2023-03-08
  • 2017-03-04
  • 2019-04-20
  • 1970-01-01
相关资源
最近更新 更多