'Column not found: 1054 Unknown column 'remember_token' in 'field list'?

Im trying to do Auth:logout();, but im getting this error. Do i really need this column or i can avoid that?

Route::get('/logout', 'MainController@logout');

  public function logout(){
      Auth::logout();

      return response()->json([
        'isLoggedIn' => false
        ]);
    }


Solution 1:[1]

Looks like you've deleted the remember_token from the users table. Laravel uses this field by default, so you can just add the field back to the table:

$table->rememberToken();

Of course you could override some of Laravel methods to disable this functionality, but I wouldn't recommend that.

Solution 2:[2]

You could avoid that by using this on your User Model.

 /**
* Overrides the method to ignore the remember token.
*/
public function setAttribute($key, $value)
{
$isRememberTokenAttribute = $key == $this->getRememberTokenName();
if (!$isRememberTokenAttribute)
{
  parent::setAttribute($key, $value);
}
}

Solution 3:[3]

Simply go to 'up' function in your create_user_table migration and add

$table->rememberToken();

to the schema remember too reset migration and carry out a fresh db:seed

Solution 4:[4]

Running php artisan migrate:fresh solved my problem. However, I did already have the migration scripts in place, ready to be executed when I run that comand.

Solution 5:[5]

You need add an upgrade for your users table.

php artisan make:migration AddToTokenToUsersTable

A file like database/migrations/2022_03_26_190557_add_to_token_to_users_table.php is created. Then you edit this file like this:

class AddToTokenToUsersTable extends Migration
{
    public function up()
    {
        Schema::table('users', function (Blueprint $table) {
            $table->rememberToken();
        });
    }

    public function down()
    {
        Schema::table('users', function (Blueprint $table) {
            $table->dropRememberToken();
        });
    }
}

Then, just run

php artisan migrate

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Alexey Mezenin
Solution 2 a3rxander
Solution 3
Solution 4 Vladimir Despotovic
Solution 5 pablorsk