调用未定义的方法BinaryFileResponse :: header()

时间:2018-12-30 21:36:56

标签: laravel laravel-5 maatwebsite-excel

在更新Maatwebsite Laravel软件包后出现了一个问题,但是他们确定这不是他们软件包中的问题。

我收到以下错误:在ModifyHeadersMiddleware.php文件中调用未定义的方法Symfony \ Component \ HttpFoundation \ BinaryFileResponse :: header()。

这通过以下控制器功能显示:

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

我的出口是这样的

<?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()
        ]);
    }
}

这是ModifyHeadersMiddle.php文件中显示的代码部分:

   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;
}

任何人都能提供的帮助,我将不胜感激。非常感谢!

1 个答案:

答案 0 :(得分:0)

use $response->headers->set().