Reputation: 12327
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 ?
Upvotes: 5
Views: 7584
Reputation: 1
Add a remember_key
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->remember_key;
}
public function setRememberToken($value)
{
$this->remember_key = $value;
}
public function getRememberTokenName()
{
return 'remember_key';
}
Upvotes: 0
Reputation: 5041
Not sure if Laravel has changed since this was originally answered, but there is a simple answer:
In your User.php file add:
protected $rememberTokenName = 'myTokenField';
As far as I can tell this value is used by the getRememberTokenName
method and therefore propagates to the rest of the code.
As Laurence indicated there may be a problem with the Database Auth driver which seems to use a hardcoded value.
Upvotes: 1
Reputation: 60048
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',
Upvotes: 2
Reputation: 7575
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';
}
Upvotes: 12