json - Laravel 从多个中选择解码的 json 变量
问题描述
假设我使用 Eloquent 'with' 从数据库中检索到以下内容。
类似 Debitur::find(7)->with('teleponDebitur')->first();
以下是数据的结构:
{
"id": 7,
"user_id": 26,
"nama": "Mr. Zachery Wisoky",
"alamat": "44967 Anissa Parkways Apt. 262\nSelmerland, MS 41916-7633",
"tanggal_lahir": "1997-04-19",
"tempat_lahir": "51697 Jakubowski Freeway Apt. 414\nLake Sydneeshire, OR 11599",
"no_ktp": "41",
"created_at": "2018-07-16 02:49:34",
"updated_at": "2018-07-16 02:49:34",
"telepon_debitur": [
{
"id": 21,
"debitur_id": 7,
"no_telepon": "6",
"created_at": "2018-07-16 02:51:17",
"updated_at": "2018-07-16 02:51:17"
},
{
"id": 32,
"debitur_id": 7,
"no_telepon": "8701",
"created_at": "2018-07-16 02:51:18",
"updated_at": "2018-07-16 02:51:18"
}
]
}
然后我解码json:
$value = json_decode($data);
@foreach($value->data as $var)
<tr>
<td>{{ $var->id }}</td>
<td>{{ $var->nama }}</td>
<td>{{ $var->alamat }}</td>
<td>{{ $var->telepon_debitur[0]->no_telepon }}</td> ????
</tr>
很好,但我不知道如何访问“telepon_debitur”中的“no_telepon”值?
解决方案
我通过浏览找到了无需 foreach 即可访问的解决方案$var->telepon_debitur[0]->no_telepon
推荐阅读
- maven-shade-plugin - 使用 maven-shade-plugin 保留所有原始类和仅来自 deps 的类
- java - TraceId 在 Java 中的分布式跟踪中未与 url 一起传递
- google-play - 未经允许使用请求访问所有文件访问权限的应用将从 Google Play 中删除,您将无法发布
- c++ - 进程的输出文本未附加到 QTextBrowser 对象
- linux - 如何将包服务安装到 alpine Linux?
- html - 具有添加文本功能的 DDlist
- reactjs - React 如何将索引传递到地图功能之外?
- c++ - C++ 预处理器:迭代逗号分隔的列表参数
- python - Subtracting values from a Pandas Dataframe in an Iterative Fashion
- tensorflow - 如何安装 TensorFlow v1?