Laravel API

Add column “api_token” in table users

ALTER TABLE `users`
CHANGE `api_token` `api_token` varchar(80) COLLATE 'utf8mb4_unicode_ci' NULL AFTER `remember_token`;

Postman issues in local

Postman doesn’t apply settings in host file, so don’t use “example.test”, change to “localhost:8000”.

Token

//Origin Token, should be used to login
$token = \Str::random(60);

$admin->forceFill([
    'api_token' => hash('sha256', $token),
])->save();

Reference:

  1. https://laravel.com/docs/5.8/api-authentication