28 lines
826 B
PHP
28 lines
826 B
PHP
<?php
|
|
|
|
namespace App\Services;
|
|
|
|
use Barryvdh\DomPDF\Facade\Pdf;
|
|
use Illuminate\Support\Facades\Auth;
|
|
|
|
class FileService
|
|
{
|
|
public function exportSubjects()
|
|
{
|
|
$listSubjects = collect();
|
|
$student = Auth::user()->userable;
|
|
$subjects = $student->grade->subjects;
|
|
$teachers = $student->grade->teachers;
|
|
|
|
$teachers->each(function ($teacher) use ($subjects, $listSubjects) {
|
|
$teacher->subjects->each(function ($subject) use ($subjects, $listSubjects, $teacher) {
|
|
if ($subjects->contains($subject)) {
|
|
$listSubjects->push(['subject' => $subject->name, 'teacher' => $teacher->fio]);
|
|
}
|
|
});
|
|
});
|
|
|
|
return Pdf::loadView('subjects.pdf', ['subjects' => $listSubjects])->download('subjects.pdf');
|
|
}
|
|
}
|