framework: Undefined constant Illuminate\Http\Request::HEADER_X_FORWARDED_ALL

  • Laravel Version: 9.0
  • PHP Version: 8.1.2
  • Database Driver & Version: mysql 8.0

Description:

I install latest version composer require fideloper/proxy:^4.4.1, but error: Undefined constant Illuminate\Http\Request::HEADER_X_FORWARDED_ALL

I don’t understand why the code doesn’t match the master branch.

Steps To Reproduce:

Screenshots

Снимок экрана 2022-02-09 в 11 48 31 Снимок экрана 2022-02-09 в 12 06 59

composer.json

"require": {
        "php": "^8.0.2",
        "doctrine/dbal": "^3.0",
        "fideloper/proxy": "^4.4.1",
        "fruitcake/laravel-cors": "^2.0",
        "guzzlehttp/guzzle": "^7.4.1",
        "intervention/image": "^2.5",
        "laravel/framework": "^9.0",
        "laravel/sanctum": "^2.14",
        "laravel/tinker": "^2.7",
        "spatie/laravel-permission": "^5.0"
    },
    "require-dev": {
        "spatie/laravel-ignition": "^1.0",
        "fakerphp/faker": "^1.9.1",
        "laravel/breeze": "^1.8",
        "laravel/sail": "^1.13.2",
        "mockery/mockery": "^1.5.0",
        "nunomaduro/collision": "^6.0",
        "phpunit/phpunit": "^9.5.0"
    },

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 3
  • Comments: 17 (3 by maintainers)

Most upvoted comments

https://laravel.com/docs/9.x/upgrade#upgrade-9.0 In document Trusted Proxies update steps already given. Please try those steps.

image

you need to delete file “config/trustedproxy.php”

If the above answer does not work for you and you are getting the same error, execute one more line for removing the trusted/proxy from composer.json.

// Before...
protected $headers = Request::HEADER_X_FORWARDED_ALL;
 
// After...
protected $headers =
    Request::HEADER_X_FORWARDED_FOR |
    Request::HEADER_X_FORWARDED_HOST |
    Request::HEADER_X_FORWARDED_PORT |
    Request::HEADER_X_FORWARDED_PROTO |
    Request::HEADER_X_FORWARDED_AWS_ELB;

This will remove the proxy from the composer.json and the exception will be gone.

composer remove trusted/proxy

it’s properly mentioned in the laravel 9 about fideloper/proxy (same way you can remove trusted proxy) in upgrade guide. https://laravel.com/docs/9.x/upgrade#the-assert-deleted-method

@driesvints the upgrade guide does not explicitly state that the package is no longer required and can be deleted. I ran into the same issue yesterday.

Even after changing out the middleware, the fideloper-package still auto-loaded its own config and ran into the error.

Maybe adding a text about removing the package would help?

@spaceemotion I see. I was a bit confused because the screenshot of the OP still showed the incorrect namespace even though it was listed in the upgrade guide. I’ll PR that to indicate you need to remove the package.

@qdmitry please read the upgrade guide carefully before posting issues.

@pragnesh87 It turns out that the fideloper/proxy package is no longer required. I change use import.