How to enable CORS in Laravel?

前端 未结 3 1069
无人及你
无人及你 2020-12-20 16:57

I am in Laravel 5.8 - I kept getting this CORS issue

\"\"

I\'ve tried

php artisan make:mi         


        
3条回答
  •  不思量自难忘°
    2020-12-20 17:55

    Add below to you .htaccess (just add to the destination site and origin site)

    Header always set Access-Control-Allow-Origin "*"
    Header always set Access-Control-Allow-Methods "POST, GET, OPTIONS, DELETE, PUT"
    Header always set Access-Control-Max-Age "1000"
    Header always set Access-Control-Allow-Headers "x-requested-with, Content-Type, origin, authorization, accept, client-security-token"
    
    RewriteEngine On
    RewriteCond %{REQUEST_METHOD} OPTIONS
    RewriteRule ^(.*)$ $1 [R=200,L]
    

    Hope it saves someone time, happy coding!!!

提交回复
热议问题