0

My collection looks like this

array:3 [▼
  "label" => array:2 [▼
    0 => "onhold"
    1 => "approved"
  ]
  "data" => array:2 [▼
    0 => 1
    1 => 1
  ]
  "chart_data" => "{"label":["onhold","approved"],"data":[1,1]}"
]

I would like to pass chart_data to my blade VIEW. It should show something like this

Onhold 1 Approved 1

I tried the following to no luck

  @foreach ($data as $datum)
  {{$datum['label']}}
  {{$datum['data']}}
  @endforeach

Would appreciate any help. Thanks!

1
  • do foreach to this array not solve your problem , you should refactoring your array to be like this $data['chart_data'] = [ onhold=>1 , 'approved' => 1 ] , key ( your label ) value ( your data ) you can print it direct , in your view or foreach if $data contain alote of items inside it Commented Feb 7, 2021 at 10:06

1 Answer 1

1

You can use @for in your blade

@for($i=0;$i<count($data);$i++)
    {{$datum['label'][$i]}}
    {{$datum['data'][$i]}}
@endfor
Sign up to request clarification or add additional context in comments.

2 Comments

you can also use @foreach($data as $i => $datum) then use that $i similarly
@bhucho Yep. There are a lot of approaches for achieving this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.