Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

abbood's avatar

how to get a user session token on laravel tinker

We always get production support tickets saying that a problem is happening with specific customers on specific api endpoints. I would like to fetch their auth token from a tinker session, then feed it to postman so that I can call that api and see exactly what they're seeing.

this doesn't work:

$user = User::find(<user_id>);
use Illuminate\Support\Facades\Auth
Auth::login($user)
PHP Warning:  unlink(/project/root/storage/framework/sessions/Ug4diWWb****): 
No such file or directory in /project/root/bootstrap/cache/compiled.php on line 7538

ideas?

0 likes
3 replies
martinbean's avatar

@abbood I imagine your default auth guard is set to use the session driver. You won’t have sessions in a command line context.

Instead, specify the name of your API’s auth guard when trying to authenticate:

Auth::guard('api')->login($user);
2 likes
djilousp's avatar

Try to use :

Auth::loginUsingId(<user_id>)

2 likes

Please or to participate in this conversation.