Laravel-excel: Can't get filename - download() method returning headers/string

Created on 6 Jun 2018  路  2Comments  路  Source: Maatwebsite/Laravel-Excel

Hi! First of all thanks for the plugin! =)
I'm using laravel 5.6 and the last version of the plugin.

adminSimulationExport.php

namespace App\Exports;

use Illuminate\Contracts\View\View;
use Maatwebsite\Excel\Concerns\FromCollection;
use Maatwebsite\Excel\Concerns\FromView;
use Maatwebsite\Excel\Concerns\FromQuery;
use Maatwebsite\Excel\Concerns\Exportable;

use App\Simulation;

class adminSimulationExport implements FromQuery
{
    use Exportable;

    public function __construct($params)
    {
        $this->orderBy = $params["orderBy"];
        $this->active = $params["active"];
        $this->direction = $params["direction"];
    }

    public function query()
    {       
      return Simulation::where('active',$this->active )->orderBy($this->orderBy, $this->direction);     
    }
}

API.PHP (routes)

$params = [];
$csv = Excel::download(new adminSimulationExport($params), 'simulations.xlsx');
// return response()->download( $csv ); 
return response()->file( $csv ); 

When trying to download/show the file i get this error:

The file "HTTP/1.0 200 OK Cache-Control: public Content-Disposition: attachment; filename="simulations.xlsx" Date: Wed, 06 Jun 2018 19:45:33 GMT Last-Modified: Wed, 06 Jun 2018 19:45:33 GMT " does not exist

I'm getting the headers. Is it supposed to work like this?
I'd like to get the path to the file i just created and download/show! =)

Thanks in advance!

question

All 2 comments

@theoarena just return Excel::download(new adminSimulationExport($params), 'simulations.xlsx') it makes a download response for it out of the box :)

Thanks, @patrickbrouwers! It麓s working now =)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

amine8ghandi8amine picture amine8ghandi8amine  路  3Comments

muhghazaliakbar picture muhghazaliakbar  路  3Comments

matthewslouismarie picture matthewslouismarie  路  3Comments

wwendorf picture wwendorf  路  3Comments

dr3ads picture dr3ads  路  3Comments