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
なぜこのエラーが発生するのかわかりません。これを機能させる方法について提案はありますか?ご協力ありがとうございました。