【发布时间】:2016-02-25 11:29:41
【问题描述】:
我正在开发类似于 CRM 应用(客户关系管理)的应用
我有以下代码获取分配给用户的$ms 数组
//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 的数组,所以我将按以下方式循环它
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);
}
上面的代码运行良好,但我需要先获取最小值,例如
在第一个循环中通知的计数 3 在第二个计数中是 2。
但我首先需要最小值所以当return $ms[$x]->notifications;
在我们的例子中,我需要返回带有最小计数的数组 2
有什么办法可以做到吗?
感谢您的宝贵时间。
【问题讨论】:
-
您只需要通知数量最少的行还是需要按通知排序的所有项目?
-
不,我需要所有项目才能为每个客户获得最少的通知数
标签: php arrays laravel laravel-4 laravel-5