我工作在App类似于CRM应用(客户关系管理)检索Laravel关系最小
我有一个分配给用户
//check if contract end or not and active or inactive
// and first_date_for_service < now()
$ms= MaintenanceService::join('cus_contract','cus_contract.id','=','maintenance_service.contract_id')
->where('cus_contract.status','=','active')
->where('cus_contract.contract_end_at','>',Carbon::now())
->where('maintenance_service.user_id', Auth::user()->id)
->where('maintenance_service.first_date_for_service','<', Carbon::now())
->get();
现在我有下面的代码,得到的$ms
阵列的$ms
阵列所以我将循环遍历它作为以下
for($x = 0; $x< count($ms);$x++) {
// here i get all notifications for $ms[$x] in each loop using Eloquent
return count($ms[$x]->notifications);
}
上面的代码运作良好,但我需要首先取最小值,为电子xample
在第一环路通知 和在第二计数的计数为。
但我需要的分钟在第一所以当return $ms[$x]->notifications;
我需要返回携带分钟计数在我们的例子
有没有办法实现这个数组?
谢谢你的时间。
您是否只需要具有最低通知次数的行或您是否需要按通知排序的所有项目? – user2479930
不,我需要所有项目才能获得每个客户的最低通知数 –