Reputation: 3444
I would like to use the auth
function in Laravel 4.2 with a custom table called pseudo
but I'm getting this error:
Undefined index: id
The PK of the table is : id_pseudo
Here is my auth.php config:
'driver' => 'database',
'table' => 'pseudo',
Here is my model for the table "pseudo" :
class pseudo extends Eloquent implements UserInterface, RemindableInterface {
protected $table = 'pseudo';
protected $primaryKey = 'id_pseudo';
/**
* Get the unique identifier for the user.
*
* @return mixed
*/
public function getAuthIdentifier()
{
return $this->id_pseudo;
}
/**
* Get the password for the user.
*
* @return string
*/
public function getAuthPassword()
{
return $this->password;
}
Here is my php code:
public function authentification()
{
$email = Input::get('email');
$mdp = Input::get('password');
if (Auth::attempt(array('email' => Input::get('email'), 'password' => Input::get('password'), 'code_court_etat' => 'VALIDE'))){
exit("signature OK");
} else {
exit("signature KO");
}
I am sure that the problem is on somewhere into the "model" file, but I do not know what exactly, I am a beginner with laravel.
Upvotes: 0
Views: 1809
Reputation: 9883
Your auth driver should be eloquent
as you're trying to use an eloquent model, rather than directly querying the database.
In your app/config/auth.php
you should also set the model option to the class of your model, in this case pseudo
More in the documentation on authentication with 4.2 http://laravel.com/docs/4.2/security
Edit as per comments:
As your current model implements both the UserInterface
and RemindableInterface
there are several methods your model needs to define for several features of the auth functionality to work.
You can add the following two traits to your model to automatically add the required functions. This assumes you have the following columns on your table: email
, password
and remember_token
use \Illuminate\Auth\Reminders\RemindableTrait, \Illuminate\Auth\Reminders\RemindableInterface;
Alternatively you can implement these methods yourself if your table uses different column names. See the 2 links below as to what methods need to be added and what they should do.
https://github.com/laravel/framework/blob/4.2/src/Illuminate/Auth/UserTrait.php https://github.com/laravel/framework/blob/4.2/src/Illuminate/Auth/Reminders/RemindableTrait.php
Upvotes: 1