I'm trying to export to Excel from Query but give me an error
Too few arguments to function App\Exports\JobExport::__construct(), 0 passed and exactly 1 expected
App\Exports:
use App\Applyed;
use Maatwebsite\Excel\Concerns\FromCollection;
use Maatwebsite\Excel\Concerns\WithHeadings;
use Maatwebsite\Excel\Concerns\FromQuery;
use Maatwebsite\Excel\Concerns\Exportable;
class JobExport implements FromQuery
{
use Exportable;
public function __construct(int $id)
{
$this->id = $id;
return $this;
}
public function query()
{
return Applyed::query()->whereId('job_id', $this->id);
}
}
Controller:
public function export($id)
{
return (new JobExport)->forId($id)->download('invoices.xlsx');
}
Route:
Route::get('job/export/{id}', 'JobsController@export');
Blade:
<a href="{{url('job/export',$job->id)}}" class="button big ripple-effect">Export to Excel</a>