laravel 未定义保护[api]的验证驱动程序[api]

lnlaulya  于 2022-11-26  发布在  其他
关注(0)|答案(1)|浏览(137)

当我在laravel lumen passport项目中登录用户并在postman上测试时,错误出现了

Auth driver [api] for guard [api] is not defined

我的登录函数是

public function login(Request $request)
    {
        
        $login_credentials=[
            'email'=>$request->email,
            'password'=>$request->password,
        ];
        if(auth()->attempt($login_credentials)){
        
            $user= auth()->user();
         
            return response()->json(['user' => $user], 200);
        }
        else{
            //wrong login credentials, return, user not authorised to our system, return error code 401
            return response()->json(['error' => 'UnAuthorised Access'], 401);
        }
    }

and the route is

$router->group(
    ['prefix' => 'v1/api',
    'middleware' => 'client'],
    function () use ($router) {
        $router->post('/register','UserController@register');
        $router->post('/login','UserController@login');
});

my boostrap/config/auth.php file is

return [
    'defaults' => [
        'guard' => 'api',
        'passwords' => 'users',
    ],
'guards' => [
        'api' => [
            'driver' => 'passport',
            'provider' => 'users',
            'hash' => true,
        ],
    ],
'providers' => [
        'users' => [
            'driver' => 'eloquent',
            'model' => \App\Models\User::class
        ]
    ]
];

'我正在尝试登录该用户我想登录该用户但出现错误

Auth driver [api] for guard [api] is not defined

我不知道该怎么做这个错误。和从哪里来的错误。如果任何人可以帮助请回复
先谢谢你,

kfgdxczn

kfgdxczn1#

看起来,您将auth.php文件放在了错误的目录中。它不应该在引导目录中,它应该在根目录中
your-project/config/auth.php

相关问题