Skip to content
This repository has been archived by the owner on Feb 16, 2023. It is now read-only.

Laravel cors are not returned #551

Open
Larnic opened this issue Jan 2, 2022 · 3 comments
Open

Laravel cors are not returned #551

Larnic opened this issue Jan 2, 2022 · 3 comments

Comments

@Larnic
Copy link

Larnic commented Jan 2, 2022

// Handle the request
$response = $next($request); ///Laravel pass to next Middleware without setting cors

    if ($request->getMethod() === 'OPTIONS') {
        $this->cors->varyHeader($response, 'Access-Control-Request-Method');
    }

    return $this->addHeaders($request, $response); // Cors are added here

Since two days i've a bug with cors bc 'im in virtual machine for back office dev machine and database but on the host for front office dev from vue.js

And tu update auth user profile the browser always throw a Cors error bc missing AllowAccessControlOrigin, and true they are never set by middleware cors package.

Laravel: 8.40
FruitCake: 2.0
PHP: 7.3.27
Chrome DevsTools

@360synertech-dev1
Copy link

this solution is not perfect but you can add headers in the routes web.php file on the top the file
I had the same problem with the chrome extension this is how I resolved it.
the laravel dd will not work with vue.js so use postman for debugging

hope this help

routes/web.php

<?php

header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: POST, GET, OPTIONS, PUT, DELETE');
header('Access-Control-Allow-Headers: Content-Type, X-Auth-Token, Origin, Authorization');

use Illuminate\Support\Facades\Route;

    /*
    |--------------------------------------------------------------------------
    | Web Routes
    |--------------------------------------------------------------------------
    |
    | Here is where you can register web routes for your application. These
    | routes are loaded by the RouteServiceProvider within a group which
    | contains the "web" middleware group. Now create something great!
    |
    */
Route::get('/', function () {
    return "hello world";
});

@BlueBazze
Copy link

+1 had the same problem

@gerciljunio
Copy link

+1 same problem here! :(

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants