'Laravel Export : Function name must be a string
Having a problem with this code
<?php
namespace App\Exports;
use App\SubmissionDetail;
use Maatwebsite\Excel\Concerns\FromCollection;
class SubmissionDetailExport implements FromCollection
{
protected $id;
function __construct($id) {
$this->id = $id;
}
/**
* @return \Illuminate\Support\Collection
*/
public function collection()
{
return SubmissionDetail::where('submission_id', $this->id)->get()([
'submission_id', 'nama_barang', 'image_path', 'jumlah', 'harga_satuan', 'harga_total', 'keterangan'
]);
}
}
it says on line 21 which is "return SubmissionDetail::where('submission_id', $this->id)->get()(["
Solution 1:[1]
You have error in your code. You typed your get() wrong. The get() method should receive parameters you want, not try to be executed as a function:
return SubmissionDetail::where('submission_id', $this->id)->get([
'submission_id', 'nama_barang', 'image_path', 'jumlah', 'harga_satuan', 'harga_total', 'keterangan'
]);
EDIT:
You can also just select fields you want from the start, without getting all the fields first, and then filtering them down:
return SubmissionDetail::select('submission_id', 'nama_barang', 'image_path', 'jumlah', 'harga_satuan', 'harga_total', 'keterangan')->where('submission_id', $this->id)->get();
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | zlatan |
