34 lines
815 B
PHP
34 lines
815 B
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace App\Exports;
|
||
|
|
|
||
|
|
use App\Models\ActivityLog;
|
||
|
|
use Maatwebsite\Excel\Concerns\FromCollection;
|
||
|
|
use Maatwebsite\Excel\Concerns\WithHeadings;
|
||
|
|
use Maatwebsite\Excel\Concerns\WithMapping;
|
||
|
|
|
||
|
|
class ActivityLogExport implements FromCollection, WithHeadings, WithMapping
|
||
|
|
{
|
||
|
|
public function collection()
|
||
|
|
{
|
||
|
|
return ActivityLog::with('user')->latest()->get();
|
||
|
|
}
|
||
|
|
|
||
|
|
// Header Excel
|
||
|
|
public function headings(): array
|
||
|
|
{
|
||
|
|
return ['Waktu', 'Pelaksana', 'Aksi', 'Deskripsi', 'IP Address'];
|
||
|
|
}
|
||
|
|
|
||
|
|
// Mapping Data per Baris
|
||
|
|
public function map($log): array
|
||
|
|
{
|
||
|
|
return [
|
||
|
|
$log->created_at->format('d/m/Y H:i:s'),
|
||
|
|
$log->user->name ?? 'System',
|
||
|
|
$log->action,
|
||
|
|
$log->description,
|
||
|
|
$log->ip_address,
|
||
|
|
];
|
||
|
|
}
|
||
|
|
}
|