php - 如何在 laravel 刀片模板中读取多级 JSON 值
问题描述
我有一个从数据库返回 JSON 值的控制器,
我的控制器:
<?php
namespace App\Http\Controllers;
use Auth;
use DB;
use App\EmployeeDetail;
class MyController extends Controller
{
public function index()
{
$employeeDetail = new EmployeeDetail();
if (Auth::check())
{
$id = Auth::user()->id;
$employeeDetail = DB::table('employee_details')->where('user_id', $id)->first();
dump($employeeDetail);
}
return view('myView', compact('employeeDetail'));
}
}
$employeeDetail 的 JSON 值:
{
"id": 1
"emp_id": "1617"
"content": "{"empId": "1617", "field1": "1111", "field2" : "2222"}",
"created_at": "2018-05-12 18:09:52"
"updated_at": "2018-05-12 18:39:30"
}
我需要知道如何在我的刀片文件中读取上述 JSON 中的值 field1 和 field2。我可以通过 {{ $employeeDetail->emp_id }} 读取 emp_id。
解决方案
推荐阅读
- r - 使用R删除时间序列中连续零值之前的行
- c++ - 如何使用 cmake 生成器表达式为不同的编译器添加编译器标志?
- spring-data - 使用 CosmosDB 中的 Spring Data 返回嵌套对象的不同值
- swiftui - swiftUI 在计算 ZStack 元素的数据之前运行函数的同步问题
- r - 使用辅助数据框定义的变量计算唯一值
- regex - 正则表达式匹配字符串中相同子字符串中的最后一个子字符串
- java - Passay 生成不是旧密码的密码
- javascript - 是否可以在 JavaScript 或 TypeScipe 的自定义类中实现索引器?
- flutter - 如何在 Flutter 的 decimalPattern 中设置 maximumFractionDigits?
- google-apps-script - 如何修复来自 Google Ads API 的无效 JSON 负载错误