有没有办法仅从中获得列名?

时间:2019-11-04 14:28:57

标签: laravel

我只想获得列名enter image description here

// item表,列new_values数据

 {"item_name":"
  Chopstick",
  "item_quantity":"4",
  "item_brand":"d",
  "item_serialno":"3",
  "item_tag":"New",
   "item_categories":"Assets",
   "item_unitcost":"4",
   "item_depriciation":"5",
   "item_location":
   "Not Deployed",
   "user_assign":"None",
   "department":"Not Assigned","id":36}

//控制器

$audits=audits::select('new_values')->get();

//刀片

   @foreach($audits as $colName => $value)
       {{ $colName }}
   @endforeach  

2 个答案:

答案 0 :(得分:1)

据我了解,您正在使用Audit model package,如果可以,则可以使用此

@foreach($audits as $audit)
    @foreach($audit->new_values as $colName => $value)
        {{ $colName }}
        // use @dd($aud->new_values, $colName) for see what is value
        // other logic
    @endforeach
@endforeach

答案 1 :(得分:1)

$json = json_decode($aud->new_values);
foreach ($json as $name => $value) {
   // Here you have your $name
}