【问题标题】:Laravel: Too few arguments to function App\Exports\JobExport::__construct(), 0 passedLaravel:函数 App\Exports\JobExport::__construct() 的参数太少,0 已通过
【发布时间】: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>

【问题讨论】:

标签: php laravel laravel-excel


【解决方案1】:

改变

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

进入

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

如果您想改用 forId() 设置器,则删除 $id 构造函数参数。

【讨论】:

  • 感谢您的评论,我使用了 return (new JobExport($id))->download('invoices.xlsx');但是给我空的excel :(
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-02-16
  • 1970-01-01
  • 2019-03-05
  • 2023-02-22
  • 2019-09-23
  • 1970-01-01
  • 2020-07-30
相关资源
最近更新 更多