I'm using facebook JS to log in users to a laravel 5 application. I'm able to add the information to the database correctly but I'm trying to log the user in manually and can't figure it out.
Here is my controller:
<?php namespace App\Http\Controllers;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Http\lib\TopAdditions;
use App\Http\lib\GeneralFunctions;
use App\User;
class FacebookLoginController extends Controller{
public function FacebookRegistration(){
$facebook = new User();
$isThereAUser = User::where('name', $_GET['name'])->get();
if(!count($isThereAUser) > 0){
$facebook->name = $_GET['name'];
$facebook->email = $_GET['email'];
$facebook->password = sha1($_GET['password']);
$facebook->remember_token = $_GET['token'];
$facebook->save();
$id = User::where('name', $_GET['name'])->get();
$this->LoginUser($id);
}
}
public function LoginUser($id){
\Auth::login($id[0]['id'],true);
}
}
When I run that and there is no such user in the database, the user is created and I get this message when the manual login is attempted:
ErrorException in Guard.php line 425: Argument 1 passed to Illuminate\Auth\Guard::login() must implement interface Illuminate\Contracts\Auth\Authenticatable, integer given
I've been searching the web for similar situations but couldn't find anything that will help...
Please help me!
You should pass the user object, not the id, to Auth::login
. So just change your function to be like this:
public function LoginUser($user){
\Auth::login($user, true);
}