I want to return my nested array in a foreach loop. In this foreach loop I need to add a foreach, because it is variable how many accordions exist.
But I can’t get it to load the data from the "accordion" array into the frontend.
There is always an error somewhere.
I can’t describe it any better right now.
Save
This is my treatments.php file:
'treatments' => [
[ /* */
'img' => asset('img/logos/Dermatologie_Dr_med_Aresu_Naderi_Nienstedten_Logo.png'),
'title' => 'Klassische Dermatologie',
'teaser' => 'Ein wesentlicher Bestandteil im Behandlungskonzept meiner Hautarztpraxis ist die ästhetische Dermatologie und Lasermedizin.',
'pop-up' => 'derma',
'accordion' => [
[
'title' => 'test',
'content' => 'test2',
],
[
'title' => 'test',
'content' => 'test2',
],
],
],
]
And this is my Frontend Blade Code:
<div class="row">
@foreach( $treatments as $key => $value)
<?php print_r($value) ?>
<div class="col-md-4 py-5">
<img class="w-100" src="{!! __($value['img']) !!}" alt="{!! __($value['title']) !!}">
</div>
<div class="col-md-8 py-5">
<span class="treatmentsHeadline">{!! __($value['title']) !!}</span>
<p class="pt-3">{!! __($value['teaser']) !!}</p>
<div class="pt-3">
<button class="button-naderi" href="#{!! __($value['pop-up']) !!}">Mehr erfahren</button>
<button class="button-naderi" href="#{!! __($value['pop-up']) !!}">Termin vereinbaren</button>
</div>
</div>
@foreach($value as $acc)
<p>{!! __($acc['title']) !!}</p>
@endforeach
@endforeach
<p class="footer-vh"></p>
</div>
2
Answers
I finaly got it!
@foreach($value as $acc)
should be@foreach($value['accordion'] as $acc)