mardi 5 février 2019

Laravel eager loading with conditional select not work

I am trying to select sum of my column value with eager loading.

My query is

$transactions = Service::with(['transactions' => function($query) use ($queryData){
        $query->whereIn('status',['Success','Pending','Successful','Processing']);
        $query->whereDate('created_at','>=', $queryData);
        $query->addSelect(DB::raw("SUM(deducted) as adjustment"));
}]);

But I am not getting any sum with my response.

my resulted response look like

"id": "3",
"name": "Service Name",
"transactions": [ ]

But It should be

"id": "3",
"name": "Service Name",
"adjustment": 30



from Newest questions tagged laravel-5 - Stack Overflow http://bit.ly/2DTX4jA
via IFTTT

Aucun commentaire:

Enregistrer un commentaire