I'm using Laravel 5.6 and this Middleware to allow Ionic app call my API's
<?php
namespace App\Http\Middleware;
use Closure;
class Cors
{
public function handle($request, Closure $next)
{
return $next($request)
->header('Access-Control-Allow-Origin', '*')
->header('Access-Control-Allow-Methods', 'GET, POST, PUT, PATCH, DELETE, OPTIONS')
->header('Access-Control-Allow-Headers', 'Content-Type, Authorization, X-Requested-With, X-XSRF-TOKEN');
}
}
So this is causing error for two requests where I'm forcing file download.
Call to undefined method Symfony\Component\HttpFoundation\BinaryFileResponse::header()
My request 1
return Excel::download(new \App\Exports\FleetExport($fleetId), 'debts.xlsx');
My request 2
return \Response::download($file_path,
$file_name,
array('Content-Type: application/octet-stream','Content-Length: '. filesize($file_path))
)->deleteFileAfterSend(true);
Disabling this middleware makes my requests works fine.
Am I doing something wrong?