i'm currently using version 3.1 of https://laravel-excel.com/ I want to query data and download them into excel file but it always returns a blank sheet.
my route:
Route::get('/reports/excel', 'ReportController@excel');
My ReportsExport Controller:
use Illuminate\Contracts\View\View;
use Maatwebsite\Excel\Concerns\FromView;
class ReportsExport implements FromView, WithEvents, ShouldAutoSize
{
use Exportable;
private $from, $to;
public function __construct(String $from, String $to) {
$this->from = $from;
$this->to = $to;
}
public function view(): View
{
return view('reports.sample', [
'reports' => Report::whereBetween('created_at', [$this->from, $this->to])->get()
]);
}
download controller
public function excel(Request $request) {
$from = Carbon::parse($request->get('from'));
$to = Carbon::parse($request->get('to'));
return Excel::download(new ReportsExport($from, $to), 'reports.xlsx');
}
Can you please let me know what i'm missing here? Any help would be appreciated. Thank you!