/home/kueuepay/public_html/app/Exports/ContactRequestExport.php
<?php

namespace App\Exports;

use Maatwebsite\Excel\Excel;
use App\Models\Frontend\ContactRequest;
use Illuminate\Support\Carbon;
use Maatwebsite\Excel\Concerns\FromCollection;
use Maatwebsite\Excel\Concerns\WithHeadings;
use Maatwebsite\Excel\Concerns\WithMapping;

class ContactRequestExport implements FromCollection, WithHeadings, WithMapping
{

    /**
    * Optional Writer Type
    */
    private $writerType = Excel::XLSX;
    
    /**
    * Optional headers
    */
    private $headers = [
        'Content-Type' => 'text/csv',
    ];

    public function headings(): array
    {
        return [
            '#',
            'Name',
            'Email',
            'Message',
            'Created At',
        ];
    }

    /**
    * @param mixed $contact
    */
    public function map($contact): array
    {
        return [
            $contact->id,
            $contact->name,
            $contact->email,
            $contact->message,
            Carbon::parse($contact->created_at)->format("d-m-Y H:i A")
        ];
    }

    /**
    * @return \Illuminate\Support\Collection
    */
    public function collection()
    {
        return ContactRequest::get(['id','name','email','message','created_at']);
    }
}
Best Practice

Best Practices

To ensure a smooth integration process and optimal performance, follow these best practices:

  1. Use secure HTTPS connections for all API requests.
  2. Implement robust error handling to handle potential issues gracefully.
  3. Regularly update your integration to stay current with any API changes or enhancements.