File: /var/www/vhost/disk-apps/qas.sports-crowd.com/app/Http/Controllers/Exports/ListTickeLogsExport.php
<?php
namespace App\Http\Controllers\Exports;
use Maatwebsite\Excel\Concerns\FromCollection;
use Maatwebsite\Excel\Concerns\WithEvents;
use Maatwebsite\Excel\Concerns\WithHeadings;
class ListTickeLogsExport implements FromCollection, WithHeadings, WithEvents
{
private $results;
public function __construct($results)
{
$this->results = $results;
}
// set the headings
public function headings(): array
{
$heading = [
__('messages.list_ticket_logs.title_1'),
__('messages.list_ticket_logs.title_2'),
__('messages.list_ticket_logs.title_3'),
__('messages.list_ticket_logs.title_4'),
__('messages.list_ticket_logs.title_5'),
__('messages.list_ticket_logs.event'),
__('messages.list_ticket_logs.date'),
];
return $heading;
}
// freeze the first row with headings
public function registerEvents(): array
{
return [];
}
public function collection()
{
foreach ($this->results as $tiketsName) {
$initialData = array(
$tiketsName->ticket_id,
$tiketsName->previousUserEmail,
$tiketsName->newUserEmail,
$tiketsName->payment_reference,
$tiketsName->number_transfers,
$tiketsName->event_,
\Carbon\Carbon::parse($tiketsName->date_)->format('Y-m-d h:i:s A'),
);
$data[] = $initialData;
}
return collect($data);
}
}