Reputation: 60
I have query :
$data = DB::select('SELECT YEAR(start_date) AS Year,
count(activity) AS qty,managing FROM data_xxx GROUP
BY(start_date),managing');
and called it in "result" view :
<div class="col-md-6">
<div class="box">
<div class="box-header with-border">
<h3 class="box-title">Statistik Realisasi Kerjasama</h3>
</div>
<!-- /.box-header -->
<div class="box-body">
<table class="table table-bordered">
<tr>
<th>Name</th>
<th>2019</th>
<th>2020</th>
<th>2021</th>
</tr>
<tr>
@foreach($data as $jj)
<td>{{$jj->managing}}</td>
<td>{{$jj->year == 2019 ? $jj->qty : ''}} </td>
<td>{{$jj->year == 2020 ? $jj->qty : ''}} </td>
<td>{{$jj->year == 2021 ? $jj->qty : ''}} </td>
@endforeach
</tr>
</table>
</div>
<!-- /.box-body -->
<div class="box-footer clearfix">
<ul class="pagination pagination-sm no-margin pull-right">
<li><a href="#">«</a></li>
<li><a href="#">1</a></li>
<li><a href="#">2</a></li>
<li><a href="#">3</a></li>
<li><a href="#">»</a></li>
</ul>
</div>
</div>
</div>
result :
how to echo it in blade so it become like this :
"2019,2020,2021" data from YEAR(start_date) AS Year
"data1 and data2" from managing
"1" from count(activity) AS qty
Upvotes: 0
Views: 79
Reputation: 15047
Just replace this:
<tr>
<th>Name</th>
<th>2019</th>
<th>2020</th>
<th>2021</th>
</tr>
<tr>
@foreach($data as $jj)
<td>{{$jj->managing}}</td>
<td>{{$jj->year == 2019 ? $jj->qty : ''}} </td>
<td>{{$jj->year == 2020 ? $jj->qty : ''}} </td>
<td>{{$jj->year == 2021 ? $jj->qty : ''}} </td>
@endforeach
</tr>
with this:
<tr>
<th>#</th>
<th>Name</th>
<th>2019</th>
<th>2020</th>
<th>2021</th>
</tr>
@foreach($data as $key => $jj)
<tr>
<td>{{$key+1}}</td>
<td>{{$jj->managing}}</td>
<td>{{$jj->year == 2019 ? $jj->qty : ''}} </td>
<td>{{$jj->year == 2020 ? $jj->qty : ''}} </td>
<td>{{$jj->year == 2021 ? $jj->qty : ''}} </td>
</tr>
@endforeach
Upvotes: 0