Cors In LARAVEL
1 . Install Package
composer require fruitcake/laravel-cors
2 . Publish Configuration
This command will create a config/cors.php
file in your Laravel project.
php artisan vendor:publish --provider="Fruitcake\Cors\CorsServiceProvider"
3 . Configure CORS Settings
Open the config/cors.php
file
return [ 'paths' => ['api/*'], 'allowed_methods' => ['*'], 'allowed_origins' => ['*'], 'allowed_origins_patterns' => [], 'allowed_headers' => ['*'], 'exposed_headers' => [], 'max_age' => 0, 'supports_credentials' => false, ];
4 . Update Middleware
In your app/Http/Kernel.php
file,
add the Fruitcake\Cors\HandleCors
middleware to the $middleware
array:
protected $middleware = [ // ... \Fruitcake\Cors\HandleCors::class, ];
http://127.0.0.1:5500/
) for POST requests using the fruitcake/laravel-cors
package, you can configure the config/cors.php
file accordingly.
No comments:
Post a Comment