Unable to authenticate user in laravel

$userdata = array( 'email' => Input::get('email'), 'password' => Input::get('password') ); if (Auth::attempt($userdata)) { echo 'SUCCESS!'; } else { return Redirect::to('login'); } 

when I launch the application from the browser, I got this error:

Argument 1 passed to Illuminate\Auth\EloquentUserProvider::validateCredentials() must be an instance of Illuminate\Auth\UserInterface, instance of User given, called in /home/srtpl17/Sites/yatin.sr/vendor/laravel/framework/src/Illuminate/Auth/Guard.php on line 316 and defined

What did I do wrong?

+7
laravel-4 basic-authentication
source share
3 answers

It seems that from your error, your user model does not implement UserInterface (the standard user model that comes with Laravel does it right, so I assume you created a custom one)

http://github.com/laravel/laravel/blob/master/app/models/User.php

Make sure the User model looks like this:

 use Illuminate\Auth\UserInterface; use Illuminate\Auth\Reminders\RemindableInterface; class User extends Eloquent implements UserInterface, RemindableInterface { /** * Get the unique identifier for the user. * * @return mixed */ public function getAuthIdentifier() { return $this->getKey(); } /** * Get the password for the user. * * @return string */ public function getAuthPassword() { return $this->password; } /** * Get the e-mail address where password reminders are sent. * * @return string */ public function getReminderEmail() { return $this->email; } // Add your other methods here } 
+7
source share

You do not show that userdata is defined as, but from the error message, it seems that this is an instance of your User model class.

The Auth::attempt() method looks for an array of credentials, not a model.

+1
source share

This error may occur when using a different model for users (for example: member) if you need to update the authentication model and authentication table in app / config / auth.php with the corresponding model / database table.

0
source share

All Articles