调用未定义的方法 BinaryFileResponse::header()
Call to undefined method BinaryFileResponse::header()
我在更新 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;
}
如果有人能提供任何帮助,我将不胜感激。非常感谢!
use $response->headers->set().
我在更新 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;
}
如果有人能提供任何帮助,我将不胜感激。非常感谢!
use $response->headers->set().