0

As defined in documentation of barryvdh/laravel-cors, I've tried to implement laravel-cors on a fresh installation of Laravel but that doesn't work.

It yet gives the error of No Access Origin.

I'm trying to access the post request using Axios on Quasar

Any assistance will be thanked.

Specs:

  1. Laravel @ v5.4
  2. Laravel-Cors @ v0.9.2
  3. Axios @ v0.16.2
  4. Quasar @ v0.14

Laravel-Cors documentation ref.

Works on Chrome if the extension of CORS is installed and enabled, but not the case without any extension in Firefox.

Hence need to make it work without any extension on all browsers.

2
  • 1
    How have you implemented it? Commented Jun 20, 2017 at 10:01
  • I added the Service provider, the global middleware, and published default config as guided in Documentation of laravel-cors. That's all I did. Commented Jun 20, 2017 at 12:09

2 Answers 2

1

you can use barryvdh/laravel-cors to allow cors
or
just add this line
header("Access-Control-Allow-Origin: *"); in the top of controller which will receive requests

and axios data will not just a JSON
you should pass it as URL search parameter using URLSearchParams object
example:

const params = new URLSearchParams();
params.append('email', email_variable);
params.append('password', password_variable);

axios.post('url_here', params)
   .then();
Sign up to request clarification or add additional context in comments.

Comments

0

Also when you need to fetch post request from one url to another is it's necessary to set mode: cors'

fetch('http://example.com/movies.json',{
      method: 'post',
      mode: 'cors',
      credentials: 'include',
      headers: {
        'Accept': 'application/json',
        'Content-Type': 'application/json'
      })
  .then((response) => {
    return response.json();
  })
  .then((myJson) => {
    console.log(myJson);
  });

Comments

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.