[英]how to distinct only one column in the foreach laravel blade
首先,抱歉我的英语不好,我做了一个包含太多连接的查询,它产生了非常复杂的 output,
这是我的controller
$detail_plotting = Detail_Plotting::select('detail_plotting.*', 'user.NAMA_USER','plotting.ID_PLOTTING','unit_kerja_prodi_homebase.STATUS_UNIT','unit_kerja_prodi_homebase.NAMA_UNIT','unit_kerja_prodi_homebase.ID_UNIT','departemen.ID_DEPARTEMEN','periode.ID_PERIODE','mata_kuliah.KODE_MK','mata_kuliah.NAMA_MK','mata_kuliah.SKS','mata_kuliah.SEMESTE')
->join('user', 'user.ID_USER', '=', 'detail_plotting.ID_USER')
->join('unit_kerja_prodi_homebase', 'unit_kerja_prodi_homebase.ID_UNIT', '=', 'user.ID_UNIT')
->join('departemen', 'departemen.ID_DEPARTEMEN', '=', 'unit_kerja_prodi_homebase.ID_DEPARTEMEN')
->join('plotting', 'plotting.ID_PLOTTING', '=', 'detail_plotting.ID_PLOTTING')
->join('periode', 'periode.ID_PERIODE', '=', 'plotting.ID_PERIODE')
->join('detail_mk', 'detail_mk.ID_DETAIL_MK', '=', 'plotting.ID_DETAIL_MK')
->join('mata_kuliah', 'detail_mk.KODE_MK', '=', 'mata_kuliah.KODE_MK')
->where('mata_kuliah.STATUS_MK',1)
->where('detail_mk.STATUS_DETAIL_MK',1)
->where('unit_kerja_prodi_homebase.STATUS_UNIT',1)
->where('unit_kerja_prodi_homebase.ID_DEPARTEMEN',Session::get('departemen'))
// ->where('user.ID_ROLE',2)
->where('periode.STATUS_PERIODE',1)
// ->latest('detail_plotting.ID_DETAIL_PLOTTING')
->orderBy('user.NAMA_USER','asc')
->get();
// $mk = MataKuliah::where('STATUS_MK',1)->get();
return view('beban-dosen-prodi.beban-dosen-prodi-index',compact('detail_plotting'));
接下来我在 laravel 刀片文件中建立了这样的视图
刀片视图
<table class="table table-bordered">
<thead>
<tr>
<th>No</th>
<th>Dosen</th>
<th>Kode MK</th>
<th>MK</th>
<th>SKS</th>
<th>Semester</th>
<th>Prodi</th>
<th>Beban</th>
<th>Total</th>
</tr>
</thead>
<tbody>
<?php $counter=1;?>
@forelse($detail_plotting as $detail_plottings)
<tr>
<td>{{ $counter }}</td>
<?php $counter++;?>
<td>{{ $detail_plottings->NAMA_USER }}</td>
<td>{{ $detail_plottings->KODE_MK }}</td>
<td>{{ $detail_plottings->NAMA_MK }}</td>
<td>{{ $detail_plottings->SKS }}</td>
<td>{{ $detail_plottings->SEMESTE }}</td>
<td>{{ $detail_plottings->NAMA_UNIT }}</td>
<td>{{ $detail_plottings->BEBAN_SKS }}</td>
<td>Total</td>
</tr>
@empty
@endforelse
</tbody>
</table>
我所做的查询是成功的,并产生了一个 output 如下图所示
我一直在阅读并寻找一些方法,例如unique()
或groupBy()
但输出不正确,因为它们只显示 2 个数据
我的问题,如何设计或其他方式使其像 distinct() 仅用于第二列
将->groupBy('user.NAMA_USER')
添加到您的查询中。
但只有在 MySQL 中禁用ONLY_FULL_GROUP_BY
模式时才会起作用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.