Excel File Doesn,t Download Directly its Shows Popup

What i want is to download file without showing popup where to save a file.it should download directly.

enter image description here

public function export_pharmacy_list()
{
    $data = Pharmacy::with('user')->get();
    $state = $this->list_of_states();
    Excel::create('Laravel Excel', function($excel) use ($data,$state) {
        $excel->sheet('Excel sheet', function($sheet) use ($data,$state) {
            $sheet->loadView('excel.pharmacy.list')->with('data',$data)->with('list_of_state',$state);
            $sheet->setOrientation('landscape');
        });
    })->export('xls');
}

Upvotes: 0

Views: 231

Answers (1)

JustAnotherPatrick
JustAnotherPatrick

Reputation: 111

You could try this

$file_url = 'http://www.myremoteserver.com/file.exe';
header('Content-Type: application/octet-stream');
header("Content-Transfer-Encoding: Binary"); 
header("Content-disposition: attachment; filename=\"" . basename($file_url) . "\""); 
readfile($file_url); // do the double-download-dance (dirty but worky)

Here is the link to the readfile documentation

This method might require you to save the file temporarily though.

Upvotes: 1

Related Questions