File: /var/www/vhost/disk-apps/qas.sports-crowd.com/app/Http/Controllers/Exports/ModuleLogsExport.php
<?php
namespace App\Http\Controllers\Exports;
use Maatwebsite\Excel\Concerns\FromCollection;
use Maatwebsite\Excel\Concerns\WithEvents;
use Maatwebsite\Excel\Concerns\WithHeadings;
class ModuleLogsExport implements FromCollection, WithHeadings, WithEvents
{
private $results;
public function __construct($results)
{
$this->results = $results;
}
// set the headings
public function headings(): array
{
return [
__('messages.module_logs.tag1'),
__('messages.module_logs.tag3'),
__('messages.module_logs.tag3'),
__('messages.module_logs.tag5-1'),
__('messages.module_logs.tag5-2'),
__('messages.module_logs.tag5-3'),
__('messages.module_logs.tag6'),
__('messages.module_logs.tag2'),
];
}
// freeze the first row with headings
public function registerEvents(): array
{
return [];
}
public function collection()
{
$data = [];
foreach ($this->results as $log) {
$data[] = array(
$log->description_operation,
$log->task,
$log->name,
$log->first_name,
$log->last_name,
$log->email,
\Carbon\Carbon::parse($log->created_at)->format('Y-m-d h:i:s A'),
$log->data_operation,
);
}
return collect($data);
}
}