I'm trying to export a csv file with Maatwebsite\Excel and Laravel 9.
As a response, I get my datas and headings in console > network , but no download occurs.
Here's my code :
Exports
namespace App\Exports;
use App\Models\Data;
use Illuminate\Support\Facades\Schema;
use Maatwebsite\Excel\Concerns\WithHeadings;
use Maatwebsite\Excel\Concerns\FromCollection;
class DataExport implements FromCollection, WithHeadings
{
/**
* @return \Illuminate\Support\Collection
*/
public function collection()
{
return Data::all();
}
public function headings():array{
return[
Schema::getColumnListing('data')
];
}
}
And my controller (1st try) :
public function download_file_csv()
{
Excel::store(new DataExport, 'dataTemplate.csv');
Excel::download(new DataExport,'dataTemplate.csv',\Maatwebsite\Excel\Excel::CSV, [
'Content-Type' => 'text/csv',
]);
}
and 2nd try
public function download_file_csv()
{
Excel::store(new DataExport, 'dataTemplate.csv');
return Excel::download(new DataExport,'dataTemplate.csv');
}
The file with datas and headings is properly stored in my public folder...
Thanks in advance,