dimanche 30 septembre 2018

Laravel query failed using function query

I am trying to get sum of amount of all users group by month.But if I add sum then query not work.It return amount log as blank array But without sum query return all logs data as monthly.

My query

$reports = $user->whereHas('groups', function ($query) use($acceptedGroup) {
    $query->whereIn('groups.name',$acceptedGroup);
})->with(
    array(
        'amountLogs' => function($query) use($year){
            $query
            ->select(
                DB::raw('sum(amount) as total')
            )
                ->whereYear('created_at','=',  $year)
                ->groupBy(DB::raw("MONTH(created_at)",'user_id'))->get();
        })
);

If I remove

            ->select(
                DB::raw('sum(amount) as total')
            )

Then query works



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2xPbi1Y
via IFTTT

Aucun commentaire:

Enregistrer un commentaire