Consider I have the following array (passed to view from my controller):
'first' => [
'1' => [
'title' => 'First Div',
'fields' => [
'name', 'select'
],
],
'divider',
'2' => [
'title' => 'Second Div',
'fields' => [
'address'
],
],
Looks like this in the browser when I dump:
array (size=2)
1 =>
array (size=2)
'title' => string 'First Div' (length=9)
'fields' =>
array (size=2)
0 => string 'name' (length=4)
1 => string 'select' (length=6)
2 =>
array (size=2)
'title' => string 'Second Div' (length=10)
'fields' =>
array (size=1)
0 => string 'address' (length=7)
What I am trying to do is the following. I want to loop through all arrays, then display a div with a title
, and within that div, loop through all the fields
for each array.
For now I am focussing on just the looping through the array and displaying the right data, so without any divs yet. So something like this:
@foreach($first as $key => $value)
// Unsure what to do here
@endforeach
I've tried a lot of things (just playing around trying to dump or echo out data), and I cannot even figure out how to display the title
, let alone loop through all the fields
values.
Either way, my ultimate goal is to create the following, dynamic view, based on what is passed from the controller: