penjadwalan-ga/app/Exports/AllKelasExport.php

43 lines
902 B
PHP

<?php
namespace App\Exports;
use App\Models\Kelas;
use Maatwebsite\Excel\Concerns\FromCollection;
use Maatwebsite\Excel\Concerns\WithMultipleSheets;
class AllKelasExport implements WithMultipleSheets
{
/**
* @return \Illuminate\Support\Collection
*/
protected $year;
public function __construct($year)
{
$this->year = $year;
}
public function sheets(): array
{
$sheets = [];
$query = Kelas::query();
if ($this->year != 'all'){
$query->whereYear('created_at', $this->year);
}
$allKelas = $query->orderBy('created_at', 'desc')->get();
if($allKelas->count() <= 0){
$sheets[] = new EmptySheetExport();
return $sheets;
}
foreach ($allKelas as $kelas) {
$sheets[] = new DetailKelasExport($kelas->id);
}
return $sheets;
}
}