Laravel:函数App \ Exports \ JobExport :: __ construct()的参数太少,传递了0

时间:2019-07-20 08:48:38

标签: php laravel laravel-excel

我正在尝试从Query导出到Excel,但给我一个错误

  

函数App \ Exports \ JobExport :: __ construct()的参数太少,0   通过并恰好有1个期望

应用\导出:

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);
}
}

控制器:

 public function export($id)
{  
    return (new JobExport)->forId($id)->download('invoices.xlsx');
}  

路线:

Route::get('job/export/{id}', 'JobsController@export');

刀片:

<a href="{{url('job/export',$job->id)}}" class="button big ripple-effect">Export to Excel</a>

1 个答案:

答案 0 :(得分:0)

更改

2147483647

进入

return (new JobExport)->forId($id)->download('invoices.xlsx');

或者如果要使用return (new JobExport($id))->download('invoices.xlsx'); 设置器,则删除$id构造函数参数。