调用未定义的方法 Symfony\Component\HttpFoundation\Response::header()
2022-08-30 18:51:29
嗨,我正在使用一个cors中间件,它似乎工作正常,直到我添加Laravel护照现在有一个问题。它显示错误
Call to undefined method Symfony\Component\HttpFoundation\Response::header() on line number 36
这是我的中间件:
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Support\Facades\Response;
class Cors
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
// ALLOW OPTIONS METHOD
$headers = [
'Access-Control-Allow-Origin' => '*',
'Access-Control-Allow-Methods' => 'POST, GET, OPTIONS, PUT, DELETE',
'Access-Control-Allow-Headers' => "Access-Control-Allow-Headers, Origin,Accept, X-Requested-With, Content-Type, Access-Control-Request-Method, Authorization , Access-Control-Request-Headers"
];
if ($request->getMethod() == "OPTIONS") {
// The client-side application can set only headers allowed in Access-Control-Allow-Headers
return Response::make('OK', 200, $headers);
}
$response = $next($request);
foreach ($headers as $key => $value)
$response->header($key, $value);
return $response;
}
}
问题是在if条件之后..任何帮助都会得到赞赏,谢谢