首页 > 解决方案 > 如何在 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。

标签: phplaravel

解决方案


推荐阅读