Kiruaaa
Kiruaaa

Reputation: 301

is there a way to only get column name out of this?

i want to get column name only if its possibleenter image description here

//item table , column new_values data

 {"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}

//controller

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

//Blade

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

Upvotes: 0

Views: 61

Answers (2)

Davit Zeynalyan
Davit Zeynalyan

Reputation: 8618

As I understand you are using Audit model package If yes then you can use this

@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

Upvotes: 1

Pavel Lint
Pavel Lint

Reputation: 3527

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

Upvotes: 1

Related Questions