Issue
I have imports:
use Maatwebsite\Excel\Concerns\FromCollection;
use App\Models\EmployeeInCompany;
use Auth;
use Maatwebsite\Excel\Concerns\Exportable;
And my Export Folder : ReportExport
class ReportExport implements FromCollection
{
use Exportable;
protected $request;
public function __construct($request)
{
$this->request = $request;
}
public function collection()
{
if ($this->request->has('filter_date')) {
$employee = EmployeeInCompany::where('company_id', Auth::user()->company_id)->get();
}else{
$employee = EmployeeInCompany::where('company_id', \Session::get('selected_company'))->get();
}
}
}
I made an export to excel. I use the code in the public function __construct to hold the $request variable for the date filter. how to solve my problem? help me, thanks.
Solution
2 options to handle this:
You can pass the request to your constructor in ReportController.php (make sure $request is defined):
new ReportExport($request);
or you can remove the parameter in the constructor and use the request helper function:
public function __construct()
{
$this->request = request();
}
Answered By - Gert B.
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.