what is token name in createToken() in Laravel Passport?

Viewed 545

I use laravel passport and I found this code for registering a user with laravel passport:

$user= User::create([
    'name' =>$request->name,
    'email'=>$request->email,
    'password'=>bcrypt($request->password)
]);

$access_token_example = $user->createToken('PassportExample@Section.io')->accessToken;

in laravel doc mention that we should pass the token name to createToken function but my question is:

I don't understand what is the usage of the token name?

we just need to produce a random token why should we give a name to it?

and another question is : what is the standard for the token name? should it be same text for all the users? can I use rand() function inside?

and the third question is: where we store the tokens? database? session?

1 Answers

may be you want to get access token instead of token name and other info.

use Laravel\Passport\HasApiTokens in user model instead of use Laravel\Sanctum\HasApiTokens

Related