Will this series help you?
Generate API key on registration
Hey all,
I'm having a painful time trying to generate an API key on registration.
I plan to only allow users to generate one key and this should be done automatically however I'm having a hard time achieving this.
Once this is done, before anyone asks. The key will always be shown on a new API Settings page.
Any help would be highly grateful :)
So create a new entry in the API tokens table, but within the create function shown?
Once you have created a personal access client, you may issue tokens for a given user using the createToken method on the User model instance. The createToken method accepts the name of the token as its first argument and an optional array of scopes as its second argument:
protected function create(array $data)
{
$user=User::create([
'name' => $data['name'],
'email' => $data['email'],
'password' => bcrypt($data['password']),
]);
$token = $user->createToken('Token Name')->accessToken;
return $user;
}
Please or to participate in this conversation.