dimanche 30 décembre 2018

Call to undefined method BinaryFileResponse::header()

I have an issue that appeared after updating the Maatwebsite Laravel Package but they are certain it isn't an issue on their package.

I get the following error: Call to undefined method Symfony\Component\HttpFoundation\BinaryFileResponse::header() in my ModifyHeadersMiddleware.php file.

This comes up through the following controller function:

public function summaryReport(){
    return Excel::download(new ClaimsExport, 'claims-report.xlsx');
}

Under which my export is as such:

<?php

namespace App\Exports;

use App\Claim;
use Maatwebsite\Excel\Concerns\FromView;
use Maatwebsite\Excel\Concerns\Exportable;
use Illuminate\Contracts\View\View;

class ClaimsExport implements FromView
{
    use Exportable;

    /**
    * @return \Illuminate\Support\Collection
    */
    public function view(): View
    {
        return view('exports.osd.claims', [
            'claims' => Claim::where('type',2)->where('status',1)->whereNotNull('shipmentID')->orderBy('claimDate','desc')->get()
        ]);
    }
}

And this is the section of code that is brought up in the ModifyHeadersMiddle.php file:

   public function handle($request, Closure $next)
{
    $headers = [
        'Access-Control-Allow-Origin'      => '*',
        'Access-Control-Allow-Methods'     => 'POST, GET, OPTIONS',
        'Access-Control-Allow-Credentials' => 'true',
        'Access-Control-Max-Age'           => '86400',
        'Access-Control-Allow-Headers'     => 'Content-Type, Authorization, X-Requested-With'
    ];

    if ($request->isMethod('OPTIONS')) {
        return response()->json('{"method":"OPTIONS"}', 200, $headers);
    }

    $response = $next($request);
    foreach($headers as $key => $value) {
        $response->header($key, $value);
    }

    return $response;
}

I'd appreciate any help anyone can give. Thank you so much!



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire