Search code examples
angularlaravellaravel-5maatwebsite-excel

How to download Excel file by Ajax in Laravel?


I use this library to export Excel

I send POST request to endpoint, where method retrieves data and creates file:

return Excel::download(new EventsExport($request), $filename);

Problem is that I get this file as binary in response, and browser does not start download it.

How to fix it?


Solution

  • I don't know anything about angular, but if you are in laravel you can,

    call a ajax request to your controller

    then create a temporary excel file with your data.

    then simply download it via this header.

    header('Content-Type: text/csv'); echo file_get_contents('your_file_location_url');

    then unlink your temp file if you want to