[英]Tymon JWTAuth for custom model which is not user model
I want to create JWT using client model. 我想使用客户端模型创建JWT。 All the login credentials are saved in the clients table. 所有登录凭据都保存在clients表中。 Here in my Laravel 5.4 application I dont want to have users model. 在我的Laravel 5.4应用程序中,我不想让用户建模。 My piece of code is being showing. 我的代码正在显示。 Now when I am trying to login laravel querying from users table which I don't. 现在,当我尝试从用户表登录laravel查询时,我没有这样做。 I want it from clients table. 我要从客户表中获取。 All the required namespaces I have added top in my controller file. 我在控制器文件中添加的所有必需的名称空间。 Need help to get a solution. 需要帮助以获得解决方案。
\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',
],
]);
I think you need to change the providers => users => model => to your custom namespace in config/auth.php 我认为您需要在config / auth.php中将providers => users => model =>更改为您的自定义名称空间
Example 例
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => App\User::class, <= change this to your custom namespace
],
],
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.