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>
Change
return (new JobExport)->forId($id)->download('invoices.xlsx');
Into
return (new JobExport($id))->download('invoices.xlsx');
Or remove the $id
constructor argument if you want to use the forId()
setter instead.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.