When I run the following code I correctly get the sum of points appended to the User model.
User::withCount([
'points' => function ($q) {
$q->select(DB::raw("SUM(points)"));
},
])
But when I run the same query using $q->selectRaw("SUM(points)") instead, Laravel returns the count of rows, and not the sum. What gives?
Whats the difference between between DB::raw and selectRaw?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire