[Vuejs]-405 Error & CORS when making an api request on localhost

0👍

Hope adding below package will help

use this https://github.com/barryvdh/laravel-cors

Installation :

composer require barryvdh/laravel-cors

Service provider :

Add this Barryvdh\Cors\ServiceProvider::class, in config/app.php

To allow CORS for all your routes, add the HandleCors middleware in the $middleware property of app/Http/Kernel.php class:

protected $middleware = [
 \Barryvdh\Cors\HandleCors::class,
 // ...
];

NOTE: make sure to place it before all middlewares

If it’s for specific middleware, on our case, it will be api

protected $middlewareGroups = [
'web' => [
   // ...
],

'api' => [
    \Barryvdh\Cors\HandleCors::class, 
    'throttle:60,1',
    'bindings',
],

];

NOTE: make sure to place it before all middlewares

Publish the config :

php artisan vendor:publish --provider="Barryvdh\Cors\ServiceProvider"

Leave a comment