1

Postman rertun this error

Illuminate\Database\QueryException: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'api_token' in 'where clause' (SQL: select * from users where api_token = B6eJj892tHBKvX186BYZgmqqqG8Iz4npy85ArvJS80boCT4UYNBD5CGDIdG6Dm5nlSi83cY3n0XTvsxj and users.deleted_at is null limit 1) in file /var/www/html/myapp/vendor/laravel/framework/src/Illuminate/Database/Connection.php on line 669

My column name in my table is token. I've also configured my storage_key in config/auth.php

'guards' => [
        'web' => [
            'driver' => 'session',
            'provider' => 'users',
        ],

        'api' => [
            'driver' => 'token',
            'provider' => 'users',
            'storage_key' => 'token',
            'input_key' => 'token',
            'hash' => false,
        ],
    ],

my ApiController.php has this code

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class ApiController extends Controller
{

    public function __Construct() {
        $this->middleware('auth:api');
    }

    public function user(Request $request) {
        return $request->user();
    }
}

And my api.php has

Route::get('user', 'ApiController@user');

I am calling my api in this way http://localhost:8000/api/user?token=myGeneratedToken

Arsalan Ahmed
  • 188
  • 1
  • 12
  • there is no api_token column in your user's table kindly create a migration and update the user's table and set an api_token, or If you choose to use a different column name, be sure to update your API's storage_key configuration option within the config/auth.php configuration file. – imran qasim Jan 30 '20 at 03:37
  • I've token column in my table, I don't want to change my column name. – Arsalan Ahmed Jan 30 '20 at 06:10
  • Duplicate of [https://stackoverflow.com/questions/46319639/how-to-change-api-token-column-in-token-guard](https://stackoverflow.com/questions/46319639/how-to-change-api-token-column-in-token-guard) I believe. – Usama Munir Jan 30 '20 at 09:25
  • for me this setting is working fine, so kindly re-confirm your token, maybe you are passing wrong token because with same settings it's working with me as well as in my tutorial – imran qasim Jan 30 '20 at 13:44
  • after running php artisan config:cache, my app works fine. – Arsalan Ahmed Jan 31 '20 at 22:12

1 Answers1

3

If you are facing the same issue, then clear your cache by using this command

php artisan config:cache

and try again

Arsalan Ahmed
  • 188
  • 1
  • 12