File: /var/www/vhost/disk-apps/demo.sports-crowd.com/app/Http/Controllers/Exports/AcademyCoachsExport.php
<?php
namespace App\Http\Controllers\Exports;
use Maatwebsite\Excel\Concerns\FromCollection;
use Maatwebsite\Excel\Concerns\WithEvents;
use Maatwebsite\Excel\Concerns\WithHeadings;
class AcademyCoachsExport implements FromCollection, WithHeadings, WithEvents
{
private $results;
public function __construct($results)
{
$this->results = $results;
}
// set the headings
public function headings(): array
{
return [
__('messages.academy_coaches.tag1'),
__('messages.academy_coaches.tag2'),
__('messages.academy_coaches.tag3'),
__('messages.academy_coaches.tag4'),
__('messages.academy_coaches.tag5'),
__('messages.academy_coaches.tag6-1'),
__('messages.academy_coaches.tag6-2'),
__('messages.academy_coaches.tag6-3'),
__('messages.academy_coaches.tag9'),
__('messages.academy_coaches.tag0'),
];
}
// freeze the first row with headings
public function registerEvents(): array
{
return [];
}
public function collection()
{
$data = [];
foreach ($this->results as $coach) {
$data[] = array(
$coach->first_name,
$coach->last_name,
$coach->email,
$coach->phone,
$coach->document,
$coach->schedules,
$coach->categories,
$coach->locations,
\Carbon\Carbon::parse($coach->created_at)->format('Y-m-d h:i:s A'),
$coach->active === 1 ? 'SI' : 'NO',
);
}
return collect($data);
}
}