====== 43 Laravel APIトークン名(api_token)を変更 ====== LaravelでAPIを作成するときに、デフォルトトークン名は、「api_token」です。 Voyagerを利用してて、この環境だとUsersのトークンカラムが「remember_token」になっていた。 そのため、remember_tokenに変更する手順をメモ Voyager 1.2 Laravel 5.8 ===== デフォルトのトークン名 ===== デフォルトのトークン名が記述されている場所は下記です。 vendor/laravel/framework/src/Illuminate/Auth/AuthManager.php: $config['input_key'] ?? 'api_token', vendor/laravel/framework/src/Illuminate/Auth/AuthManager.php: $config['storage_key'] ?? 'api_token', vendor/laravel/framework/src/Illuminate/Auth/TokenGuard.php: $inputKey = 'api_token', vendor/laravel/framework/src/Illuminate/Auth/TokenGuard.php: $storageKey = 'api_token', ===== カスタムガード作成 ===== ===== カスタムガードをアプリに登録 ===== 'App\Policies\ModelPolicy', ]; /** * Register any authentication / authorization services. * * @return void */ public function boot() { $this->registerPolicies(); $this->app['auth']->extend('remember_token', function($app, $name, array $config) { return new MyTokenGuard(Auth::createUserProvider($config['provider']), $app['request']); }); // } } ===== app/config/auth.php ===== あとは設定のdriverを修正してあげるだけ 'guards' => [ 'api' => [ 'driver' => 'remember_token', 'provider' => 'users', 'hash' => false, ], {{tag>Laravel}}