1

I am trying to make a json request to laravel from a different URL and am getting the following error back:

XMLHttpRequest cannot load http://api.core/v1.0/accounting/items/. Origin http://site.dev is not allowed by Access-Control-Allow-Origin.

I tried setting this in my after filter with no luck. I am using NGINX:

App::after(function($request, $response)
{
    $response->headers->set('Access-Control-Allow-Origin', '*');
    return $response;
});

3 Answers 3

1

Maybe you must set that header on .htaccess file if using Apache, or use option --disable-web-security if using chrome browser.

Please read this link.

nginx configuration:

add_header Access-Control-Allow-Origin *;

Sign up to request clarification or add additional context in comments.

Comments

0

Try to put the code in the before filter App::before

Comments

0

In your after filter yoy can directly use php's header method to set the headers

header('Access-Control-Allow-Origin', '*')

1 Comment

Also, it's not a method, it's a global function.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.