Anons79 Mini Shell

Directory : /home/aplikasiposinfo/public_html/talent.gosepakat.id/app/Exports/
Upload File :
Current File : /home/aplikasiposinfo/public_html/talent.gosepakat.id/app/Exports/PelatihanPesertasExport.php

<?php

namespace App\Exports;

use App\Models\PelatihanPeserta;
use Maatwebsite\Excel\Concerns\FromCollection;
use Maatwebsite\Excel\Concerns\ShouldAutoSize;
use Maatwebsite\Excel\Concerns\WithCustomValueBinder;
use Maatwebsite\Excel\Concerns\WithHeadings;
use Maatwebsite\Excel\Concerns\WithMapping;
use PhpOffice\PhpSpreadsheet\Cell\Cell;
use PhpOffice\PhpSpreadsheet\Cell\DataType;
use PhpOffice\PhpSpreadsheet\Cell\DefaultValueBinder;

class PelatihanPesertasExport extends DefaultValueBinder implements FromCollection,WithHeadings,WithMapping,ShouldAutoSize,WithCustomValueBinder
{   
    public $pelatihan_id;

    public function __construct($pelatihan_id)
    {   
       $this->pelatihan_id = $pelatihan_id;
    }

    /**
    * @return \Illuminate\Support\Collection
    */
    public function collection()
    {
        return PelatihanPeserta::has('peserta')->with('peserta','pelatihan')->where('pelatihan_id', $this->pelatihan_id)->get();
    }

    public function headings(): array
    {
        return [
            'MENDAFTAR',
            'NIK',
            'NAMA',
            'EMAIL',
            'NO HP/WA',
            'KABUPATEN/KOTA',
            'KECAMATAN',
            'KELURAHAN/DESA',
            'STATUS'
        ];
    }

    public function map($data): array
    {
        return [
            $data->created_at->format('Y-m-d H:i:s'),
            $data->peserta->nik,
            $data->peserta->nama_lengkap,
            $data->peserta->email,
            $data->peserta->no_hp,
            $data->peserta->kabupaten->name,
            $data->peserta->kecamatan->name,
            $data->peserta->kelurahan->name,
            $data->status
        ];
    }

    public function bindValue(Cell $cell, $value)
    {
        if (is_numeric($value)) {
            $cell->setValueExplicit($value, DataType::TYPE_STRING2);

            return true;
        }

        // else return default behavior
        return parent::bindValue($cell, $value);
    }
}

Anons79 File Manager Version 1.0, Coded By Anons79
Email: [email protected]