'Duplicate Data When Select With Eloquent
I'm trying to create detail page of this question's project. When I tried to get the data, it duplicate for 47 times (I have 47 data for each report) like this. What I need is only one data in a row and then the second data in the next row, etc.. This also happened on the edit page.
My view:
@foreach($sasarans as $i => $sasaran)
@foreach($sasaran->indikator as $indikator)
@foreach($indikator->pertanyaan as $pertanyaan)
<tr>
@if($loop->first)
<td style="text-align:center; vertical-align:middle;" rowspan="{{$indikator->pertanyaan->count()}}">{{$i+1}} </td>
<td style="vertical-align:middle;" rowspan="{{$indikator->pertanyaan->count()}}">{{$sasaran->sasaran}} </td>
<td style="vertical-align:middle;" rowspan="{{$indikator->pertanyaan->count()}}">{{ $indikator->indikator}} </td>
@endif
<td style="vertical-align:middle;">{{ $pertanyaan->pertanyaan}}</td>
@foreach($data_laporans as $data)
<td>{{$data->jumlah}}</td>
<td>{{$data->keterangan}}</td>
<td><a href="{{ route('data.download', $data->id) }}" class="btn btn-sm btn-default btn-block"><i class="fa fa-download"></i> Unduh Bukti</a></td>
@endforeach
</tr>
@endforeach
@endforeach
@endforeach
Controller:
public function show($id)
{
$sasarans = Sasaran::all();
$laporan_indikators = LaporanIndikator::where('id',$id)->first();
$data_laporans = DataLaporan::where('id_laporan',$id)->get();
return view('indikator-kinerja.show',compact('laporan_indikators','data_laporans','sasarans'));
}
I also tried to executed my query in phpMyAdmin and there's no duplicate data. Data in PhpMyAdmin
You can take a look for the model relationship and another details in this question. I'm so sorry for my bad English. Please help me because I'm still beginner. Thank you.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
