43 lines
912 B
PHP
43 lines
912 B
PHP
<?php
|
|
|
|
namespace App\Exports;
|
|
|
|
use App\Models\Events;
|
|
use Maatwebsite\Excel\Concerns\FromCollection;
|
|
use Maatwebsite\Excel\Concerns\WithMultipleSheets;
|
|
|
|
class AllEventsExport implements WithMultipleSheets
|
|
{
|
|
/**
|
|
* @return \Illuminate\Support\Collection
|
|
*/
|
|
protected $year;
|
|
|
|
public function __construct($year)
|
|
{
|
|
$this->year = $year;
|
|
}
|
|
public function sheets(): array
|
|
{
|
|
$sheets = [];
|
|
|
|
$query = Events::query();
|
|
|
|
if ($this->year != 'all'){
|
|
$query->whereYear('tanggal_event', $this->year);
|
|
}
|
|
$allEvents = $query->orderBy('created_at', 'desc')->get();
|
|
|
|
if($allEvents->count() <= 0){
|
|
$sheets[] = new EmptySheetExport();
|
|
return $sheets;
|
|
}
|
|
|
|
foreach ($allEvents as $event) {
|
|
$sheets[] = new PesertaEventExport($event->id);
|
|
}
|
|
|
|
return $sheets;
|
|
}
|
|
}
|