API route for laravel 5.2 Access-Control-Allow-Origin

Posted 1 year ago by eddieace

Hey, I'm trying to build an API from a Laravel 5.2 app.

What i do is return data as this.

return response()->json($data);

Live on the server it works to call this API from an url.

But when I try to access it from another application running laravel 5.4. and using Vuejs it returns this error.

XMLHttpRequest cannot load https://mysite.com/api/v1/user?token=xxxxx. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://mysecondsite.com' is therefore not allowed access.

The request from vue looks like this.

        created() {
                .then(response => {
                .catch(error => {

any clues?

Please sign in or create an account to participate in this conversation.

Laracasts Mascot

Hi, Have We Met Yet?

Did you know that, in addition to the forum, Laracasts includes well over 1000 lessons on modern web development? All for the price of one lunch out per month.

Sign Me Up


Reply to

Use Markdown with GitHub-flavored code blocks.