I am trying to export records to a CSV which queries a relation but my file keeps returning nothing but the headings.
I am making use of the laravel-excel package to do this.
Controller Method
public function export(Team $team) { return Excel::download(new TeamMembersExport(), 'team_members.csv'); }
Team Method
public function members(){ return User::with('games')->whereHas('games', function ($q) { $q->where('team_id', $this->id); })->get(); }
Export file
class ProviderMembersExport implements WithMapping, WithHeadings { public function map($team): array { $members = $team->members()->only([ 'name', 'team_number', 'date_of_birth' ]); return $members->all(); } public function headings(): array { return [ 'Name', 'Team Number', 'Date of Birth' ]; } }
Am i writing this incorrectly inside the mapping method?
https://stackoverflow.com/questions/67421841/laravel-excel-export-relationship-data May 07, 2021 at 12:00AM
没有评论:
发表评论