Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 815
Gaetan Sobze Avatar asked Jan 28 '26 22:01

Gaetan Sobze


2 Answers

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 
{

}
like image 68
Jeemusu Avatar answered Jan 31 '26 15:01

Jeemusu


@Gaetan you are getting this not found error, because you are using the
use Illuminate\Contracts\Auth\Authenticable
instead using
use Illuminate\Contracts\Auth\Authenticatable;

you user model should be like that:

use Illuminate\Database\Eloquent\Model;
use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Auth\Authenticatable as AuthenticableTrait; 

class User extends Model implements Authenticatable 
{
// your code here
}

change Authenticable with Authenticatable.

like image 24
Ornelio Chauque Avatar answered Jan 31 '26 15:01

Ornelio Chauque