I want to export data to excel from $id, but an error occurred when I added the constructor in App/Export/NilaiExport. thanks
NilaiController.php
function download($id){
return Excel::download(new NilaiExport, 'Nilai.xlsx');
}
NilaiExport.php
<?php
namespace App\Exports;
use App\Khs;
use Maatwebsite\Excel\Concerns\FromCollection;
class NilaiExport implements FromCollection
{
/**
* @return \Illuminate\Support\Collection
*/
protected $id;
public function __construct($id) {
$this->id = $id;
}
public function collection()
{
return Khs::findOrFail($this->id);
}
}