标签: laravel eloquent scope relationship
我正在尝试在 User 模型中为相关交易总额超过 $x 的用户创建一个范围。我似乎无法得到它。我尝试了以下方法:
return $query->withCount(['transactions as total' => function($query) { $query->select(DB::raw('COALESCE(sum(amount),0) as total'))->where('total', '>', $x); }]);