Question

        $userdata = array(
            'email' => Input::get('email'),
            'password'  => Input::get('password')
            );



        if (Auth::attempt($userdata)) {

            echo 'SUCCESS!';

        } else {        

            return Redirect::to('login');

        }

when i run the application from 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 have I done incorrectly?

Was it helpful?

Solution

It sounds like from your error that your User model does not implement UserInterface (the default User Model that comes with Laravel does this properly, so I'm guessing you made a custom one)

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

Make sure that 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

}

OTHER TIPS

You don't show what userdata is defined as, but from the error message it seems like it's an instance of your User model class.

The Auth::attempt() method is looking for an array of the credentials not a model.

This error might also appear when you use a different model for users (example :member) if it's the case you need to update Authentication Model and Authentication Table in app/config/auth.php with the appropriate model / database table.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top