0
votes

I Can Access this result as return $value and can access user_id as $retun $value->user_id

{
    "id": 250,
    "user_id": 53,
    "meta": {
        "sub_total": 2050,
        "charge": 0,
  
    }
}

How Can I access the sub_total like the same way? I have Tried $value->meta('sub_total') got error

1

1 Answers

0
votes

because meta not method to call . meta is attribute in your object , so you can try to access it like this :- $value->meta->sub_total , or you can convert $value to array and access its indexs like this: $value['meta']['sub_total']; , and you can avoiding errors by using optional method like this :- optional($value['meta'])['sub_total'] or optional($value->meta)->sub_total