Snippets

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

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.

Thanks.