I try to export a csv file with some data, but with my current code I get response 200, and some strange characters, and no download, not sure why.
Source URL here.
Exports/DataExport.php
namespace App\Exports;
use App\ViewData;
use Maatwebsite\Excel\Concerns\FromCollection;
use Excel;
class DataExport implements FromCollection
{
/**
* @return \Illuminate\Support\Collection
*/
public function collection()
{
return ViewData::all();
}
}
Controller
use App\ViewData;
use App\Exports\DataExport;
use Maatwebsite\Excel\Facades\Excel;
.....
// Export CSV data
public function export()
{
return Excel::download(new DataExport, 'data.xlsx');
}
I added in config/app.php file, service provider and aliase.