lessons = $lessons; $this->students = $students; } /** * @return \Illuminate\Support\Collection */ public function collection() { $result = collect(); $headRow = collect(); $headRow->push(''); $this->lessons->each(function ($lesson) use ($headRow) { $headRow->push($lesson->date); }); $result->push($headRow); $headRow = collect(); $headRow->push('ФИО'); $this->lessons->each(function ($lesson) use ($headRow) { $headRow->push($lesson->shortType); }); $result->push($headRow); $this->students->each(function ($student) use ($result){ $row = collect(); $row->push($student->fio); $this->lessons->each(function ($lesson) use ($row, $student) { $row->push($student->lessons->find($lesson->id)->pivot->score ?? ScoreEnum::WithoutScore); }); $result->push($row); }); return $result; } public function title(): string { return 'Журнал'; } public function styles(Worksheet $sheet) { $sheet->getStyle($sheet->calculateWorksheetDimension()) ->getAlignment() ->setHorizontal(Alignment::HORIZONTAL_CENTER); } }