Skip to content

Instantly share code, notes, and snippets.

@mikehins
Last active February 7, 2023 16:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikehins/4dcf7be3de0c16f6655fa281fa8ac7e1 to your computer and use it in GitHub Desktop.
Save mikehins/4dcf7be3de0c16f6655fa281fa8ac7e1 to your computer and use it in GitHub Desktop.
Route::post('/token', function () {
if (app()->environment() !== 'local') {
return ['error' => 'Not authorized'];
}
$sanctum = new Sanctum::$personalAccessTokenModel;
$user = $sanctum->where('token', request()->token)->firstOrFail();
$token = User::findOrFail($user->id)->createToken(request()->token);
return ['token' => $token->plainTextToken];
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment