Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel and Passport getting SQLSTATE[42S22]: Column not found: 1054 Unknown column 'api_token'

I've seen many posts about this error, but none of the solutions are working for me.

I'm running Laravel with Passport which is working fine on my development server. As expected, when attempting to check if a user is authenticated on my development server, it returns the catch (inside an axios call):

Development Server

"message":"Unauthenticated."

However, when running the same code on my production server, it returns the catch:

Production Server:

"message": "SQLSTATE[42S22]: Column not found: 1054 Unknown column 'api_token'
in 'where clause' (SQL: select * from `users` where `api_token` = ...

I have have run Passport migration and ['guards']['api']['driver'] set to passport in config/auth.php, and updated the configuration cache that apparently solved the problem for others.

It looks like authentication needs to use the oauth tables from passport migration, but the query appears to be looking at the user table.

EDIT:

I was able to determine that my development server uses the RequestGuard class to find user and my production server uses the TokenGuard class to find user.

like image 607
mjpsr11 Avatar asked Oct 31 '19 13:10

mjpsr11


2 Answers

I have faced the same problem. And I am using Laravel Passport. It all about configuration. got to config/auth.php and change driver name of api array to passport within the guards array

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

    'api' => [
        'driver' => 'passport',//instead of token 
        'provider' => 'users',
        'hash' => false,
    ],
],
like image 104
Ziaur Rahman Avatar answered Oct 13 '22 03:10

Ziaur Rahman


I was facing same problem and i have solve this by

php artisan config:clear
php artisan config:cache
php artisan cache:clear

may be it helpful

like image 37
Mujahid Khan Avatar answered Oct 13 '22 03:10

Mujahid Khan