File: /var/www/vhost/disk-apps/agile-selling-wpb/app/Http/Controllers/Exports/ReportClients.php
<?php
namespace App\Http\Controllers\Exports;
use App\User;
use Maatwebsite\Excel\Concerns\FromCollection;
use Maatwebsite\Excel\Concerns\WithEvents;
use Maatwebsite\Excel\Concerns\WithHeadings;
use Maatwebsite\Excel\Events\AfterSheet;
class ReportClients implements FromCollection, WithHeadings, WithEvents {
// set the headings
public function headings(): array
{
return [
'Email', 'Nombres', 'Teléfono', 'Fecha registro'
];
}
// freeze the first row with headings
public function registerEvents(): array
{
return [];
}
public function collection()
{
$users = User::where('rol_id', 4)->get();
$data = [];
foreach ($users as $user) {
$data[] = array(
$user->email, $user->first_name . ' ' . $user->last_name, $user->phone, $user->created_at,
);
}
return collect($data);
}
}