Reputation: 107
in there i want to show data from my controller to my view but i geting error. so now i want to ask how ? let me show my code.
this my controller :
public function getBulan($nama)
{
$data['users'] = DB::table('lembur_karyawan')
->select('nama', DB::raw('SEC_TO_TIME( SUM( TIME_TO_SEC( total ) ) ) as total_lembur'))
->groupBy('nama')
->havingRaw('SUM(total)')
->get();
return view('bulan_user',$data);
}
and this is my view :
<?php echo $users->{'total_lembur'} ?>
have someone know how ? i have no idea how to do it .
Upvotes: 0
Views: 871
Reputation: 2426
Do what @Md Mahfuzur Rahman has suggested.
Then in the view, you will have to run a foreach loop.
@foreach($users as $user)
{{ $user->total_lembur }}
@endforeach
Upvotes: 0
Reputation: 7149
No need to use variable data
.
Use like,
$users = DB::table('lembur_karyawan')
->select('nama', DB::raw('SEC_TO_TIME( SUM( TIME_TO_SEC( total ) ) ) as total_lembur'))
->groupBy('nama')
->havingRaw('SUM(total)')
->get();
return view('bulan_user', ['users' => $users]);
Print it in your view like,
@foreach($users as $user)
{{ $user->total_lembur }}
@endforeach
Upvotes: 1
Reputation: 2359
You can use compact
also like this:
public function getBulan($nama)
{
$users = DB::table('lembur_karyawan')
->select('nama', DB::raw('SEC_TO_TIME( SUM( TIME_TO_SEC( total ) ) ) as total_lembur'))
->groupBy('nama')
->havingRaw('SUM(total)')
->get();
return view('bulan_user', compact('users'));
}
In the view
:
{{ $user->total_lembur }}
Upvotes: 0