Answer the question
In order to leave comments, you need to log in
How to enable CORS support in Laravel?
I need the application to be able to accept cors requests, I don't need to use the api yet, but just return a response from the web group, but I still need to pass the session (withCredentials). I tried to use the fruitcake / laravel-cors package, it helped and I was able to process requests, but I could not transfer the session. I tried to do it through custom middleware:
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\Request;
class HanldeRequest
{
public function handle($request, Closure $next)
{
return $next($request)
->header('Access-Control-Allow-Origin', '*')
->header('Access-Control-Allow-Credentials',true)
->header('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS');
}
}
export const instance = axios.create({
withCredentials: true,
baseURL: "http://site.local",
headers: {
Accept: "application/json" ,
"Access-Control-Allow-Origin": 'http://localhost:3000',
"Access-Control-Allow-Credentials": true
},
});
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question