我想使用客户端模型创建JWT。所有登录凭据都保存在clients表中。在我的Laravel 5.4应用程序中,我不想让用户建模。我的代码正在显示。现在,当我尝试从用户表中登录laravel查询时,我不会这样做。我希望它来自客户表。我在控制器文件中添加了所有必需的命名空间。需要帮助来获得解决方案。
\Config::set('jwt.user', 'App\Client');
\Config::set('auth.providers.users.model', \App\Client::class);
$credentials = ["username"=>$user_name,"password"=>$password];
$token = null;
try {
if (!$token = JWTAuth::attempt($credentials)) {
return response()->json([
'response' => 'error',
'message' => 'invalid_email_or_password',
]);
}
} catch (JWTAuthException $e) {
return response()->json([
'response' => 'error',
'message' => 'failed_to_create_token',
]);
}
return response()->json([
'response' => 'success',
'result' => [
'token' => $token,
'message' => 'I am front user',
],
]);
答案 0 :(得分:0)
我认为您需要将Provider => users => model =>更改为config / auth.php中的自定义名称空间
示例
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => App\User::class, <= change this to your custom namespace
],
],