60 lines
1.3 KiB
PHP
Executable File
60 lines
1.3 KiB
PHP
Executable File
<?php
|
|
|
|
namespace App\DB\Te;
|
|
|
|
use Illuminate\Support\Arr;
|
|
use Maatwebsite\Excel\Concerns\FromCollection;
|
|
use Maatwebsite\Excel\Concerns\ShouldAutoSize;
|
|
use Maatwebsite\Excel\Concerns\WithHeadings;
|
|
use Maatwebsite\Excel\Concerns\WithEvents;
|
|
use Maatwebsite\Excel\Events\BeforeExport;
|
|
use Maatwebsite\Excel\Events\AfterSheet;
|
|
|
|
class ExcelCollection implements FromCollection, WithHeadings, ShouldAutoSize, WithEvents
|
|
{
|
|
|
|
|
|
/**
|
|
* TableEngineExport constructor.
|
|
*/
|
|
public function __construct($export, $cols)
|
|
{
|
|
$this->export = $export;
|
|
$this->show = array_keys($cols);
|
|
$this->head = array_values($cols);
|
|
}
|
|
|
|
public function collection()
|
|
{
|
|
|
|
return $this->export->map(function ($value, $key) {
|
|
|
|
$exp = [];
|
|
$all = $value->toArray();
|
|
foreach ($this->show as $val) {
|
|
$exp[$val] = Arr::get($all, $val);
|
|
}
|
|
return collect($exp);
|
|
});
|
|
}
|
|
|
|
|
|
public function registerEvents(): array
|
|
{
|
|
return [
|
|
AfterSheet::class => function (AfterSheet $event) {
|
|
$event->sheet->getDelegate()->setRightToLeft(true);
|
|
},
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
public function headings(): array
|
|
{
|
|
return $this->head;
|
|
}
|
|
}
|
|
|