database - Laravel JWT return data from two tables
问题描述
I am using JWT authentication via api.php
when a user login to the route
Route::post('login', 'AuthController@login');
he reached this method in auth controller
protected function respondWithToken($token)
{
return response()->json([
'access_token' => $token,
'token_type' => 'bearer',
'expires_in' => auth()->factory()->getTTL() * 1000,
'user' => auth()->user()
]);
}
Here 'user' => auth()->user()
is returning the data from user table,
I have another table user_Details in which all user information is saved, I want to fetch details from that table to when some one login,
Help me out please.
解决方案
我找到了另一种简单的方法来做到这一点
protected function respondWithToken($token)
{
return response()->json([
'access_token' => $token,
'token_type' => 'bearer',
'expires_in' => auth()->factory()->getTTL() * 1000,
'user' => auth()->user(),
'user_detail' => user_detail::where('user_id','=',auth()->user()->id)->get()
]);
}
推荐阅读
- cobol - CICS 子程序
- tensorflow - 如何在 Keras 上向 Tensorboard 添加文本摘要?
- groovy - Groovy Micronaut 的 @Client 注入 RxHttpClient 与 RxHttpClient.create 有什么区别?
- javascript - Notepad++ 不会执行 if else 语句中的条件,即使它执行了我的提示功能?
- javascript - JS 通过嵌套 json 创建自定义 json
- angular - Angular Material - 在组件级别覆盖覆盖 css
- go - 如何在 Go 1.11+ for Golang 中使用 GOPATH 之外的整体 repo 架构共享本地模块
- java - 使用 Map 的方法 merge()
将字符串附加到 StringBuilder(value) - linux - 无法为 python 链接共享库
- vue.js - RouterLink 在 Vue Js 中未正确显示