5

I am trying to authenticate our user using the API token,

Here is my code config/auth.php code

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

        'api' => [
            'driver' => 'token',
            'provider' => 'users',
        ],
    ],

My Api.php is like this

Route::group(['middleware' => ['subdomain_setup','auth::api'],'prefix'=>'v1'], function () {
    Route::get('getCoupons','Api\CouponAPI@getCoupons');
});

Now I am getting this error while accessing my api URL

Column not found: 1054 Unknown column 'api_token' in 'where clause' (SQL: select * from users where api_token =

2
  • does your users table have a token column? are you sure it shouldn't be another table? Commented Sep 26, 2017 at 11:29
  • @delboy1978uk yes my users table have api_token column Commented Sep 26, 2017 at 14:00

3 Answers 3

14

Make sure you have run Passport migration and ['guards']['api']['driver'] set to passport in config/auth.php, and updated the configuration cache

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

    'api' => [ 
        'driver' => 'passport', 
        'provider' => 'users', 
    ], 
],
Sign up to request clarification or add additional context in comments.

1 Comment

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

You must alter table to add a 'api_token' field.

Schema::create('users', function (Blueprint $table) {
    $table->increments('id');
    $table->string('name');
    $table->string('email')->unique();
    $table->string('password');

    //Add api_token field
    $table->string('api_token', 60)->unique();

    $table->rememberToken();
    $table->timestamps();
});

1 Comment

additional instructions on setting up api tokens in the docs laravel.com/docs/5.8/api-authentication#database-preparation
1

Clear the cache :

Clear Application Cache Run the following command to clear application cache of the Laravel application.

php artisan cache:clear

Clear config cache You can use config:clear to clear the config cache of the Laravel application.

php artisan config:clear

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.