how i get judul in view, i try @foreach ($blocks as $object) {{ $blocks->judul }} @endforeach
and @foreach ($blocks as $object){{ $object['figure_id'] }} @endforeach but i got error Undefined index: figure_id (View: /home/kevinhermawan/Music/FULL BACKUP FROM 159/aspirasi-web/resources/views/pages/pemilihan/mulai-page.blade.php)
post it here as i told you: so if anyone opens your question they could see it here not by going on another site and provide you with a solution that way it will be faster. anyways try to dd($blocks) and check if you have a property there called judul...
<div class="card" style="width: 18rem;">
<img class="card-img-top" src="" alt="Card image cap">
<div class="card-body">
<h5 class="card-title">{{ $object->judul }}</h5>
<p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
<a href="#" class="btn btn-primary">Go somewhere</a>
</div>
</div>
@endforeach ```
controller
``` $blocks = array();
foreach($hostels as $hostel) {
$blocks[] = DB::table('pasangan_calon')->where('id', $hostel->pasangan_calon_id)->get();
}
return view('pages/pemilihan/mulai-page', compact('blocks', 'data', 'election')); ```
ok @Dickyperdian in your controller, remove $block = array(); and change the code inside the foreach as follows:
foreach($hostels as $hostel) {
$blocks = collect(DB::table('pasangan_calon')->where('id', $hostel->pasangan_calon_id)->get());
}
here instead of storing your data inside an array we are storing it inside a collection, in your view as is, you are iterating over a collection. so just update your controller you will be good to go. for example;
@if(count($blocks)>0)
@foreach($blocks as $block)
{{$block->judul}}
//now you can access anything inside the blocks as $block->propertyName
@endforeach
@else
No data
@endif