php artisan config:publish cors
dd($user->tokens);
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I am testing my auth api that is built on Laravel Sanctrum. In the test i am using Sanctrum::actingAs method, and it gives this error:
Call to undefined method App\Models\User::token()
By the way, I already have HasApiTokens in my User model. I have tried a lot, but still haven't figured it out. Your help would be very appreciated.
For refference, this is the Pest test:
it('logs out', function () {
$user = User::factory()->create();
Sanctum::actingAs($user, ['*']);
$response = $this->postJson('/api/auth/logout');
$response->dump();
$response->assertSuccessful();
$this->assertCount(0, $user->tokens);
});
Please or to participate in this conversation.