File: /var/www/vhost/disk-apps/agile-selling-orl/app/Http/Controllers/Exports/ReportClientsNever.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 ReportClientsNever 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::whereNotIn('id', function ($query) {
$query->select('client_id')->from('orders');
})->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);
}
}