当前位置: 首页 > 工具软件 > auth-jwt > 使用案例 >

安装jwt-auth

邬飞捷
2023-12-01

1、修改composer.json文件,在 require中添加

"tymon/jwt-auth": "^1.0.0-rc.1"

2、然后使用命令行,进入项目目录,执行

composer update
php artisan vendor:publish --provider="Tymon\JWTAuth\Providers\LaravelServiceProvider"
'guards' => [
    'web' => [
        'driver' => 'session',
        'provider' => 'users',
    ],

    'api' => [
        'driver' => 'jwt',
        'provider' => 'students',
    ],
],
'providers' => [
    'users' => [
        'driver' => 'eloquent',
        'model' => App\Models\Admin\Admin::class,
    ],

    'students' => [
        'driver' => 'eloquent',
        'model' => App\Models\Api\User::class,
    ],
],

3、转跳官网继续

4、将Auth::guard()修改为Auth::guard("api");

5、生成密钥

php artisan jwt:secret

6、访问http://localhost:8000/api/auth/login

 类似资料: