我工作在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
不,我需要所有項目才能獲得每個客戶的最低通知數 –