I want to integrate Laravel with Angular. I can get the token becouse I ad this in cors.php
'paths' => ['api/*', 'sanctum/csrf-cookie', **'oauth/*'**],
But any another secure route doesn’t work (display CORS error). I tryued use middleware
return $next($request)
->header('Access-Control-Allow-Origin', '*')
->header('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS')
->header('Access-Control-Allow-Headers', 'X-Requested-With, Content-Type, X-Token-Auth, Authorization');
I registered that in Kernel.php and I added that in Kernel. Finally I added this middleware in my routing
Route::group(['middleware' => ['cors', 'json.response']], function () {
Route::get('/user', 'UserController@user')->middleware(['auth:api']);
});
But all the time I have a cors error. Any Idea how can I solve this?
How solve the problem with cors?
2
Answers
Try with default settings and then try to modify it if necessary.
No need to add other middleware, cause cors.php has default configuration which introduced by Laravel Team from Laravel 7.
Install
fruitcake/laravel-cors
In
config/app.php
->providers
Then in terminal
And finally in
app/Http/Kernel.php
Or