, . , Passport, . . , , , Response, middleware
, Illuminate\Http\Response
, Response, header('Header-Key', 'Header-Value')
, , Passport, Symfony\Component\HttpFoundation\Response
Call to undefined method Symfony\Component\HttpFoundation\Response::header()
, , . , , , .
$response = $next($request);
$IlluminateResponse = 'Illuminate\Http\Response';
$SymfonyResopnse = 'Symfony\Component\HttpFoundation\Response';
$headers = [
'Access-Control-Allow-Origin' => '*',
'Access-Control-Allow-Methods' => 'POST, GET, OPTIONS, PUT, PATCH, 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($response instanceof $IlluminateResponse) {
foreach ($headers as $key => $value) {
$response->header($key, $value);
}
return $response;
}
if($response instanceof $SymfonyResopnse) {
foreach ($headers as $key => $value) {
$response->headers->set($key, $value);
}
return $response;
}
return $response;
Kernel.php
protected $middleware = [
\App\Http\Middleware\Cors::class,
];