RSS

How to enable CORS in Laravel 5

20 Apr
How to enable CORS in Laravel 5

1. Add middleware
php artisan make:middleware Cors

return $next($request)
->header(‘Access-Control-Allow-Origin’, ‘*’)
->header(‘Access-Control-Allow-Methods’, ‘GET, POST, PUT, DELETE, OPTIONS’);

2. Register middleware as a route middleware

3. Use middleware in routes which support CORS

Advertisements
 
1 Comment

Posted by on April 20, 2017 in Laravel

 

Tags: ,

One response to “How to enable CORS in Laravel 5

  1. Online interview questions

    December 4, 2017 at 10:48 pm

    Check this tutorial for fixing Laravel access-control-allow-origin error in Laravel 5.5
    http://www.laravelinterviewquestions.com/2017/12/cross-origin-request-blocked-error-laravel.html

     

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: