Gaetan Sobze Gaetan Sobze - 3 months ago 20
MySQL Question

Problems with authentication with Laravel 5

I am trying to login a user with laravel 5.
Here is my controller

public function postLogin(LoginRequest $request){

$remember = ($request->has('remember'))? true : false;

$auth = Auth::attempt([
'email'=>$request->email,
'password'=>$request->password,
'active'=>true
],$remember);

if($auth){
return redirect()->intended('/home');
}
else{
return redirect()->route('login')->with('fail','user not identified');
}

}


When i enter wrong credentials, everything works fine, but when i enter the right one, i got this error message:

ErrorException in EloquentUserProvider.php line 110:
Argument 1 passed to Illuminate\Auth\EloquentUserProvider::validateCredentials() must be an instance of Illuminate\Contracts\Auth\Authenticatable, instance of App\Models\User given, called in C:\xampp\htdocs\Projects\Pedagogia\Admin.pedagogia\vendor\laravel\framework\src\Illuminate\Auth\Guard.php on line 390 and defined


I don't see where i did wrong

Answer

Argument 1 passed to Illuminate\Auth\EloquentUserProvider::validateCredentials() must be an instance of Illuminate\Contracts\Auth\Authenticatable, instance of App\Models\User given.

The validateCredentials() method of the Illuminate\Auth\EloquentUserProvider class expects an instance of Illuminate\Contracts\Auth\Authenticable, but you are passing it an instance of App\Models\User. To put it simply, your user model needs to implement the Illuminate\Contracts\Auth\Authenticable interface to work with Laravels authentication scaffolding.

Your App\Models\User model should look like this:

use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Auth\Authenticable as AuthenticableTrait;

class User extends \Eloquent implements Authenticatable 
{

}
Comments