Reputation: 159
I my app i want to fetch all orders group by date at created_at
field in laravel
but it is timestamp all date are same but time is different i want to get all data on only date wise not time
but group by not working i google it but not found any proper solution.
so how can we do that any body help thanks in advance
this is the result http://prntscr.com/nr8xjm
$query = DB::table('tms_driver');
$query->join('tms_booking', 'tms_driver.dv_id', '=', 'tms_booking.dv_id');
$query->where('tms_booking.dv_id', $request->id);
$query->where('tms_booking.tms_booking_status', '1');
$query->orderBy('tms_booking.tms_booking_id', 'DESC');
$query->groupBy('tms_booking.created_at');
$query->select('tms_booking.created_at as booking_date','tms_booking.total_paid', DB::raw('count(tms_booking.tms_booking_id) as total_booking'));
$performances = $query->get();
Upvotes: 1
Views: 1580
Reputation: 2872
you can group by date this way
->groupBy(DB::raw('Date(tms_booking.created_at)'))
or use Carbon in closure, for example
->groupBy(function ($item) {
return Carbon::parse($item->created_at)->format('Y-m-d');
})
Upvotes: 1