Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing laravel remember_token field to something else

For my project i use the Auth login, everything works fine until i try to logout with :

  Auth::logout();

I use a custom fieldname herrinerToken instead of the default remember_token. In my model/user.php i edited the function getRememberToken() to:

 public function getRememberTokenName()
{
    return 'herrinerToken';
}

when i try to logout now i get the message:

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'remember_token' in 'field list' (SQL: update gebruikers set herrinerToken = a3eYy1IIbX1FfPhPgmYNTNLwkE7A43vgqwpSU2B5b3EFNHl0ayYF1vUSGCbc, remember_token = a3eYy1IIbX1FfPhPgmYNTNLwkE7A43vgqwpSU2B5b3EFNHl0ayYF1vUSGCbc where id = 6)

So it looks like it tries tu update both remember_token and herrinerToken but i only want to update the herinner_token field. What do i need to adjust to only update the herrinerToken field and not the remember_token field ?

like image 664
Sven van den Boogaart Avatar asked May 16 '14 20:05

Sven van den Boogaart


2 Answers

Add a herrinerToken column instead of remember_token column to your users (or equivalent) database table.

You should use along with that the following snippet:

public function getRememberToken()
{
    return $this->herrinerToken;
}

public function setRememberToken($value)
{
    $this->herrinerToken = $value;
}

public function getRememberTokenName()
{
    return 'herrinerToken';
}
like image 52
menjaraz Avatar answered Oct 13 '22 16:10

menjaraz


I looked into this. It turns out that the field name 'remember_token' is actually hard coded into the DatabaseUserProvider - so even if you change it in your model - Laravel will still look for 'remember_token' if you are using the Database Auth Driver.

You need to switch to the Eloquent auth driver. It seems as though you are using Eloquent for your user model anyway - so there should be now issue switching.

Change the following setup in your app/config/auth.php file that Eloquent is being used - that should fix this issue for now:

return array(

    /*
    |--------------------------------------------------------------------------
    | Default Authentication Driver
    |--------------------------------------------------------------------------
    |
    | This option controls the authentication driver that will be utilized.
    | This driver manages the retrieval and authentication of the users
    | attempting to get access to protected areas of your application.
    |
    | Supported: "database", "eloquent"
    |
    */

    'driver' => 'eloquent',
like image 42
Laurence Avatar answered Oct 13 '22 15:10

Laurence