protected $appends=['tags','email','telephone','deals'];
(...)
public function getEmailAttribute()
{
$this->loadMissing('teamleaderCompanyEmails');
return $this->teamleaderCompanyEmails->where('type','=','primary')->implode('email',',');
}
In my controller when I:
return TeamleaderCompany::get(['email']);
it returns :
Undefined column: 7 ERROR: column "email" does not exist LINE 1: select "email" from "teamleader_companies" ^ (SQL: select "email" from "teamleader_companies")
If you add the interfaces Maatwebsite\Excel\Concerns\WithHeadings and Maatwebsite\Excel\Concerns\WithMapping to your export class, you can do this a lot easier IMO.
In your export class, you will then just need to add the methods that are required by each interface:
public function headings(): array
{
return ['email']; // add any other columns needed
}
public function map($row): array
{
// $row will be a single model instance passed in to here
return [$row->email]; // add the data from the columns defined in "headings()"
}