CORS Middleware in Laravel 6

Do you have issue like cors header ‘access-control-allow-origin’ missing in laravel or how to use cors middleware in laravel  than i will show you how to work with cors(Cross-Origin Resource Sharing) in laravel application.

Here I will show you step by step explanation “How to use cors middleware in laravel 6”.

 

Step 1:-  First we will install barryvdh/laravel-cors composer package by following composer command in your laravel application for manage cors.

After successfully install package, need to add service provider and alias in config app.php file

 

Now we need to use in middleware kernel file

Step 2:- In this step we need to create aPI Routes for testing. so open your “routes/api.php” file and add routes.

 

Step 3:- Now I am going to access this api route from another server, For that I have created a html file and try to access my api using jquery ajax.

 

I hope you might have understood it properly, keep reading our other blogs posts for more coding tricks.

Thanks!!

Add a Comment

Your email address will not be published. Required fields are marked *