Reputation: 235
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
Upvotes: 2
Views: 6030
Reputation: 361
@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.
Upvotes: 2
Reputation: 10533
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
{
}
Upvotes: 7