execute( Company::query()->with([ 'employees', 'segments', 'contacts' ]), ['business_type' => 2] ); } public function map($company): array { $employeeEmail = ''; if ($company->employees->first()) { $employeeEmail = $company->employees->first()->email; } $contactPhone = ''; if ($company->contacts->first()) { $contactPhone = $company->contacts->first()->phone; } $segments = ''; if ($company->segments->first()) { $segments = $company->segments->pluck('name')->implode(', '); } return [ $company->reference, $company->name, $contactPhone, $employeeEmail, $company->created_at ? $company->created_at->toDateString() : '', $company->updated_at ? $company->updated_at->toDateString() : '', $company->debtor, $segments, ]; } }