Noela
Noela

Reputation: 17

No 'Access-Control-Allow-Origin' header is present on the requested resource laravel 5.8.8

I have installed barryvdh/laravel-cors as explained on the readme file in the github repository. I still have a No 'Access-Control-Allow-Origin' header is present on the requested resource error. I am using vue, axios and laravel 5.8.8

Installed barryvdh/laravel-cors as well as added headers in my api.php file

My cors.php file looks like this

'supportsCredentials' => false,
    'allowedOrigins' => ['*'],
    'allowedOriginsPatterns' => [],
    'allowedHeaders' => ['Content-Type', 'X-Requested-With', 
                    'Origin','Authorization'],
    'allowedMethods' => ['*'],
    'exposedHeaders' => [],
    'maxAge' => 0,

In debugger tools i get the following

GENERAL
Request URL:http://localhost:8000/api/entriesoff
Request Method:OPTIONS
Status Code:200 OK
Remote Address:127.0.0.1:8000
Referrer Policy:no-referrer-when-downgrade
Response Headers
Allow:GET, POST, HEAD, CONNECT, PUT, DELETE, OPTIONS, PROPFIND, MKCOL
DAV:1
Request Headers
Provisional headers are shown
Access-Control-Request-Headers:x-csrf-token,x-requested-with
Access-Control-Request-Method:GET
Origin:http://127.0.0.1:8000
Referer:http://127.0.0.1:8000/

Upvotes: -1

Views: 1219

Answers (2)

Noela
Noela

Reputation: 17

I found a solution. I added index.php in my axios URL , for example http://127.0.0.1:8000/index.php/api/...

Upvotes: 0

Amin Jafari
Amin Jafari

Reputation: 429

you will use

header('Access-Control-Allow-Origin: *');

header('Access-Control-Allow-Methods: GET, PUT, POST, DELETE, OPTIONS'); header('Access-Control-Allow-Headers: Content-Type, Authorization, X-Requested-With');

instead of barryvdh/laravel-cors

in

public/index.php 

above

require __DIR__.'/../bootstrap/autoload.php';

sample:

header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, PUT, POST, DELETE, OPTIONS');
header('Access-Control-Allow-Headers: Content-Type, Authorization, X-Requested-With');
require __DIR__.'/../bootstrap/autoload.php';

Upvotes: -1

Related Questions