MIF_E31210529/app/Exports/UserExport.php

39 lines
864 B
PHP

<?php
namespace App\Exports;
use App\Models\User;
use Maatwebsite\Excel\Concerns\FromCollection;
use Maatwebsite\Excel\Concerns\WithHeadings;
use Maatwebsite\Excel\Concerns\ShouldAutoSize;
class UserExport implements FromCollection, WithHeadings, ShouldAutoSize
{
/**
* @return \Illuminate\Support\Collection
*/
public function collection()
{
return User::all()->map(function ($user, $index) {
return [
'No' => $index + 1,
'Name' => $user->name,
'Username' =>$user->username,
'Email' => $user->email,
'Role' => $user->role,
];
});
}
public function headings(): array
{
return [
'No',
'Nama',
'Username',
'Email',
'Role',
];
}
}