<?php

namespace App\Exports;

use App\Models\Designation;
use Maatwebsite\Excel\Concerns\FromCollection;
use Maatwebsite\Excel\Concerns\WithHeadings;

class DesignationExport implements FromCollection, WithHeadings
{
    /**
     * Headings for the export.
     */
    public function headings(): array
    {
        return ['Sr.', 'Designation'];
    }

    /**
     * Collection of rows for Excel export.
     */
    public function collection()
    {
        $data = Designation::latest('designation')
->whereNull('deleted_at')
->get();

        // Add serial numbers
        $sr = 1;
        return $data->map(function ($row) use (&$sr) {
            return [
                $sr++,
                strip_tags($row->designation)
            ];
        });
    }
}
