In laravel 10, I want to use sanctum, but when I send the token in the header, it gives this error:
Column not found: 1054 Unknown column 'api_token' in 'where clause' (Connection: mysql, SQL: select * from users where api_token = ld1bmhdVFj6RksdEInavxFvSmVzGfAZD7GGm9mnW12591d0f limit 1)
It looks for the api_token column in the users table! But I didn't see any mention of this column in any training!
api.php
Route::group(['middleware' => 'auth:sanctum'], function () {
Route::get('user', [UserController::class, 'user'])->name('user');
});
auth.php
'guards' => [
'web' => [
'driver' => 'session',
'provider' => 'users',
],
'api' => [
'driver' => 'token',
'provider' => 'users',
'hash' => false,
],
],
sanctum.php
'guard' => ['api']
when you use the 'driver' => 'token' then you need to add the below migration:
this is tokenguard authentication. If you want to use the Sanctum then you need to put the 'driver' => 'sanctum' Let me know if you still face any error.