And how are you passing the data to the Export class?
You cannot use $this-> within the export class and expect to use data from your livewire component, you'll have to pass it to the export class.
So in your Export class add this:
public $jobStatus;
public $workType;
public $startDate;
public $endDate;
public function __construct($jobStatus, $workType, $startDate, $endDate)
{
$this->jobStatus = $jobStatus;
$this->workType = $workType;
$this->startDate = $startDate;
$this->endDate = $endDate;
}
public function view(): View {
$report_list = JobOrder::when($this->jobStatus, function($query) {
$query->where('status', $this->jobStatus);
})
->when($this->workType, function($query) {
$query->where('job_type', $this->workType);
})
->when($this->startDate && $this->endDate, function($query) {
$query->where('created_at', '>=',$this->startDate)
->where('created_at', '<=', $this->endDate);
})
->get();
dd($report_list);
return view('layouts.exports.job-report-listing',[
'report_listing' => $report_list
]);
}
And in your component
return Excel::download(new JobOrderExport($this->status, $this->job_type_id, $this->start_date, $this->end_date), 'ReportListing.xlsx');
I tried to use your variables, but ofc make sure you use the correct ones. But that's the process.