Courses

How to Build Laravel 11 API From Scratch

What is CORS and How to Handle it?

Summary of this lesson:
- Understanding CORS in API context
- Laravel CORS configuration
- Handling cross-origin requests between different domains

Now, let's talk about Cross-Origin Resource Sharing (CORS). It seems like a very complicated topic. You can read about it in the developer.mozilla.org, but I will try to summarize it in the shortest possible way.

By default, in Laravel, you don't need to change anything, but you need to understand where to look if something goes wrong.


CORS isn't a Laravel or a PHP thing. It's how the browsers work. By default, if you try to open one resource from another domain resource, it's usually about web domains, you may run into a CORS error:

In Laravel, CORS settings are set in the config/cors.php file; by default, it allows everything.

I have cloned the same Vue.js project into a different directory. So now, I have project.test as a frontend and demo.test as an API. I changed the API call to use...

The full lesson is only for Premium Members.
Want to access all 23 lessons of this course? (58 min read)

You also get:

  • 69 courses (majority in latest Laravel 11)
  • Premium tutorials
  • Access to repositories
  • Private Discord