Reputation: 2072
In my modal I have finction getMyGroups
like this:
foreach($groups as $group){
$questions[] = array($group -> name => Question::where('group_id',$group-> group_id));
}
return $questions;
This will be returnet to the Controller:
if(is_numeric($id)){
return view('project',array('groups' => $mygroups->getMyGroups($id)));
}else{
return redirect('home');
}
So in blade I need to get:
This key $group -> name
from first function in h1 tag and values into p tag, like this:
<h1> This is first key </h1>
<p>this is 1. value for first key</p>
<p>this is 2. value for first key</p>
<p>this is 3. value for first key</p>
...
<h1> This is second key </h1>
<p>this is 1. value for second key</p>
<p>this is 2. value for second key</p>
<p>this is 3. value for second key</p>
...
Array from $groups:
array:2 [▼
0 => array:1 [▼
"key123" => Builder {#213 ▼
#query: Builder {#218 ▶}
#model: Question {#217 ▶}
#eagerLoad: []
#macros: []
#onDelete: null
#passthru: array:12 [▶]
}
]
1 => array:1 [▼
"key2" => Builder {#215 ▼
#query: Builder {#207 ▶}
#model: Question {#208 ▶}
#eagerLoad: []
#macros: []
#onDelete: null
#passthru: array:12 [▶]
}
]
]
Upvotes: 0
Views: 1301
Reputation: 72961
Blade has a @foreach()
which should get you started:
@foreach ($groups as $group => $name)
<h1> This is {{ $name }} </h1>
<p>this is ...</p>
@endforeach
You will need to adjust the markup depending on your array structure. Possible using a nested @foreach
to display the paragraphs.
Upvotes: 1