I'm using Laravel Passport API to communicate between Laravel and external "agents" via Personal Access Tokens: https://laravel.com/docs/5.5/passport#personal-access-tokens
You can create tokens: via $token = \Auth::user()->createToken('name')->accessToken;
($token then holds only the token itself, not the object)
How can I get the token()->id
for a newly created token?
I need to get the ID to store it in the database to make relation to other table.
You should split the token creation:
First create the object, this returns a Laravel\Passport\PersonalAccessTokenResult Object:
$tokenobj = \Auth::user()->createToken('name');
Then you can get the accessToken itself via:
$token = $tokenobj->accessToken;
And the token id via:
$token_id = $tokenobj->token->id;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With