How to add Access-Control-Allow-Origin header response in Laravel

2 years ago

There are few ways to add Access-Control-Allow-Origin in header response in Laravel globally. However, I will show you the easiest way to add CORS that I have discovered recently.

Go to bootstrap/app.php file and add the following code-

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

It should work now.


Thouhedu Islam Suchi

Thouhedul Islam

Laravel Developer

Hi, I am a Laravel Developer with a passion for web development. I specialize in PHP, particularly Laravel, as well as Javascript, MySql, and other cutting-edge web technologies.

During the day, I work for GLEIF, where I apply my skills and experience to develop innovative web applications. At night, I enjoy contributing to the community and solving problems. You can often find me on Laracasts, where I love to stay active and keep up-to-date with the latest trends in web development.

I am excited about the potential of technology and its power to transform people's lives.