Reputation: 299
I have attendance table then I perform count to total all the Present(P)Absent(A)Late(L) now how can I show it to blade template inside the html input with 3 separated value example: value=P, value=A, value=L; right now with my code I'm getting it as all
controller:
public function get_status(){
$from = date('2018-01-01');
$to = date('2018-03-31');
$atnds = DB::table('attendances')
->select(DB::raw('count(*) as total, status'))
->where('status', '<>', 'status')
->whereBetween('days', [$from,$to])
->groupBy('status')
->where('lead_id', '=', 1)
->get();
return view('total',compact('atnds'));}
DD RESULT
[{"total":7,"status":"A"},{"total":9,"status":"L"},{"total":65,"status":"P"}]
Upvotes: 0
Views: 539
Reputation: 8287
If you want with input then you can use it like this
<table style="width:100%">
<tr><th>Status </th> <th>Total</th></tr>
@foreach($atnds as $at)
<tr>
<td>{{ $at->status }}</td>
<td><input type="text" value ="{{ $at->total }}" /></td>
</tr>
@endforeach
</table>
Upvotes: 2
Reputation: 1848
In blade you could use
<table style="width:100%">
@foreach($atnds as $ad)
<tr>
<td>{{ $ad->total }}</td>
<td>{{ $ad->status }}</td>
</tr>
@endforeach
</table>
If you want to break them out i would do so before returning it to the blade
$status = []
foreach($atnds as $ad) {
$status[$ad->status] => $ad->total
}
$status = collect($status);
return view('total',compact('status'));
and in the blade you should now be able to do
{{ $status->L }}
or
{{ $status['L'] }}
Upvotes: 1