$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?
Just run php artisan make:auth and php artisan migrate in a fresh Laravel application. Then, navigate your browser to http://your-app.test/register or any other URL that is assigned to your application. These two commands will take care of scaffolding your entire authentication system!
Retrieving The Authenticated Useruse Illuminate\Support\Facades\Auth; // Retrieve the currently authenticated user... $user = Auth::user(); // Retrieve the currently authenticated user's ID...
The attempt method accepts an array of key / value pairs as its first argument. The password value will be hashed. The other values in the array will be used to find the user in your database table. So, in the example above, the user will be retrieved by the value of the email column.
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
}
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With