我正在尝试使用带有 Facebook 登录的 Laravel 4 设置身份验证系统。我正在为 Laravel 4 使用 madewithlove/laravel-oauth2 包。
当然,在用户使用 Facebook 登录时,没有密码可以添加到我的数据库中。但是,我正在尝试检查数据库中是否已经存在用户 ID,以确定我是应该创建一个新实体,还是只登录当前实体。我想使用 Auth 命令来执行此操作。我有一张叫做“粉丝”的桌子。
这就是我正在使用的:
$fan = Fan::where('fbid', '=', $user['uid']);
if(is_null($fan)) {
$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;
$fan->image = $user['image'];
$fan->save();
return Redirect::to('fans/home');
}
else {
Auth::login($fan);
return Redirect::to('fans/home');
}
风扇型号:
<?php
class Fan extends Eloquent {
protected $guarded = array();
public static $rules = array();
}
当我运行它时,我收到错误:
Argument 1 passed to Illuminate\Auth\Guard::login() must be an instance of Illuminate\Auth\UserInterface, instance of Illuminate\Database\Eloquent\Builder given
编辑:当我使用:$fan = Fan::where('fbid', '=', $user['uid'])->first();
我得到错误:
Argument 1 passed to Illuminate\Auth\Guard::login() must be an instance of Illuminate\Auth\UserInterface, null given, called in /Applications/MAMP/htdocs/crowdsets/laravel-master/vendor/laravel/framework/src/Illuminate/Auth/Guard.php on line 368 and defined
我不知道为什么它给了我这个错误。您对我如何使这项工作有建议吗?谢谢您的帮助。