【发布时间】:2019-07-20 08:48:38
【问题描述】:
我正在尝试从 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>
【问题讨论】:
-
This helps me a lot.希望对你也有帮助。
标签: php laravel laravel-excel