If you are using Laravel 5.5
& Laravel 5.x
and facing same problem like No 'Access-Control-Allow-Origin' header is present on the requested resource
. Just use following package and config your system.
Step 1:
composer require barryvdh/laravel-cors
Step 2
You also need to add CorsServiceProvider
to your config/app.php
providers array:
FruitCakeCorsCorsServiceProvider::class,
To allow CORS
for all your routes, add the HandleCors
middleware in the $middleware
property of app/Http/Kernel.php
class:
For global uses:
protected $middleware = [
// ...
FruitcakeCorsHandleCors::class,
];
For middleware uses:
protected $middlewareGroups = [
'web' => [
// ...
],
'api' => [
// ...
FruitcakeCorsHandleCors::class,
],
];
Step 3
Once your installation completed run below command to publish the vendor files.
php artisan vendor:publish --provider="FruitcakeCorsServiceProvider"
Hope this answer helps someone facing the same problem as myself.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…