Я хочу получить количество оповещений, которые находятся в:
Код: Выделить всё
companies -> sites -> interventions -> purchases -> alerts
Код: Выделить всё
contractors -> actions
Код: Выделить всё
companies -> actions
Код: Выделить всё
$companies = Company::where('id', '=', Auth::user()->userable_id)->orWhere('company_id', '=', Auth::user()->userable_id)->pluck('id')->toArray();
$contractors = Contractor::where('id', '=', Auth::user()->userable_id)->orWhere('company_id', '=', Auth::user()->userable_id)->pluck('id')->toArray();
$cp = array_merge($companies, $contractors);
$sites = Site::whereIn('company_id', $companies)->pluck('id')->toArray();
$interventions = Intervention::whereIn('site_id', $sites)->pluck('id')->toArray();
$purchases = Purchase::whereIn('intervention_id', $interventions)->pluck('id')->toArray();
$bubblecounts['alerts'] = Alerts::whereIn('purchase_id', $purchases)->where('status', 0)->whereDate('alert_date', '!=', '0000-00-00 00:00:00')->count();
$bubblecounts['actions'] = Action::whereIn('actionable_id', $cp)->where([['status', 0], ['alert_date', '!=', null]])->count();
Подробнее здесь: https://stackoverflow.com/questions/445 ... tions-deep