I am trying to set up an authentication system with Laravel 4 using Facebook login. I am using the madewithlove / laravel-oauth2 package for Laravel 4.
Of course, there is no password to add to my database when a user logs in with Facebook. However, I am trying to check if there is a user ID in the database to determine if I should create a new object or just enter the current one. I would like to use Auth commands for this. I have a table called "fans."
This is what I work with:
$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'); }
Fan Model:
<?php class Fan extends Eloquent { protected $guarded = array(); public static $rules = array(); }
When I ran this, I get an error message:
Argument 1 passed to Illuminate\Auth\Guard::login() must be an instance of Illuminate\Auth\UserInterface, instance of Illuminate\Database\Eloquent\Builder given
EDIT: When I use: $fan = Fan::where('fbid', '=', $user['uid'])->first();
I get an error message:
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
I do not know why he gives me this error. Do you have any suggestions on how I can do this? Thanks for the help.
source share