It throws Undefined property: stdClass::$aggregate error.
$dealers = System::entity()->getDealers()->pluck('id')->toArray();
$dealerGroups = System::entity()->getDealerGroups()->pluck('id')->toArray();
$query = Agenda::notReport()
->select('agendas.*')
->with(['agendable', 'type', 'status', 'recipients'])
->where('agendas.entity_type', 'App\Entities\Dealer')
->whereIn('agendas.entity_id', $dealers);
$dealerGroupQuery = Agenda::notReport()
->select('agendas.*')
->with(['agendable', 'type', 'status', 'recipients'])
->where('agendas.entity_type', 'App\Entities\DealerGroup')
->whereIn('agendas.entity_id', $dealerGroups);
$query = $query->union($dealerGroupQuery)
->orderBy('visit_date', 'asc');
return $query->paginate();
Also, other solution would be appreciated how to write these two queries in one query to avoid merging of them.
