Edit File: DelegatesExport.php
<?php namespace App\Exports; use App\Models\User; use App\Models\DelegateJoinrequest; use Maatwebsite\Excel\Concerns\FromArray; use Maatwebsite\Excel\Concerns\FromCollection; use Maatwebsite\Excel\Concerns\FromQuery; use Maatwebsite\Excel\Concerns\WithHeadings; use Auth; class DelegatesExport implements FromArray, WithHeadings { public function __construct($type){ $this->type = $type; } public function headings(): array { return [ __('delegates_dashboard.name') , __('delegates_dashboard.phone'), __('delegates_dashboard.nationality'), __('delegates_dashboard.city'), __('delegates_dashboard.created_at'), ]; } public function array(): array { $users = User::where('company_id',Auth::user()->id) ->where('status',$this->type) ->where('type','delegate') ->orderBy('created_at','desc') ->get(); $data[]=[]; foreach($users as $user){ $data[] = [ __('delegates_dashbaord.name') => $user->name, __('delegates_dashbaord.phone') => '0'.$user->fullPhone, __('delegates_dashbaord.nationality') => $user->delegateJoinRequests->first()->nationality->name, __('delegates_dashbaord.city') =>$user->delegateJoinRequests->first()->city->name, __('delegates_dashbaord.created_at') => date('Y-m-d H:i', strtotime($user->created_at)) ]; } return $data; } }
Back to File Manager