Getting error while updating laravel from 5.5 to 5.7 (Undefined class constant 'HEADER_CLIENT_IP')

10,485

Solution 1

At composer.json Change fideloper/proxy

From

"fideloper/proxy": "~3.3",

To

"fideloper/proxy": "^4.0",

After that run

composer update

Solution 2

1) change your composer.json to following

"php": ">=7.1.3",
"fideloper/proxy": "^4.0",
"laravel/framework": "5.7.*",
"laravel/tinker": "~1.0",

2) change your App\Http\Middleware\TrustProxies.php to following

<?php

namespace App\Http\Middleware;

use Illuminate\Http\Request;
use Fideloper\Proxy\TrustProxies as Middleware;

class TrustProxies extends Middleware
{
    /**
     * The trusted proxies for this application.
     *
     * @var array|string
     */
    protected $proxies;
    /**
     * The headers that should be used to detect proxies.
     *
     * @var int
     */
    protected $headers = Request::HEADER_X_FORWARDED_ALL;
}

3) remove the file from the config directory having name trustedproxy.php if exist

4) run the following command into the console from your application directory

composer update

5) this step is not necessary but it will clear all cache and autoload files

php artisan clear-compiled

composer dump-autoload

php artisan cache:clear

php artisan config:clear

php artisan view:clear

Solution 3

If you guys getting this error while updating to laravel 9.0 then remove below line of code from composer.json

"fideloper/proxy": "^4.4.1",

And run composer update command in terminal

composer update

Then, change the use Fideloper\Proxy\TrustProxies as Middleware; to use Illuminate\Http\Middleware\TrustProxies as Middleware; in a file app\Http\Middleware\TrustProxies.php file

Share:
10,485
alphal
Author by

alphal

Updated on June 06, 2022

Comments

  • alphal
    alphal almost 2 years

    i am getting this error.

    Undefined class constant 'HEADER_CLIENT_IP' Script @php artisan package:discover handling the post-autoload-dump event returned with error code 1

    I changed

    app\Http\Middleware\TrustedProxies.php by:
    
        <?php
    
      namespace App\Http\Middleware;
    
      use Illuminate\Http\Request;
      use Fideloper\Proxy\TrustProxies as Middleware;
    
      class TrustProxies extends Middleware
      {
        protected $proxies;
        protected $headers = Request::HEADER_X_FORWARDED_ALL;
      }
    

    Here is my .composerjson file

    {
        "name": "laravel/laravel",
        "description": "The Laravel Framework.",
        "keywords": ["framework", "laravel"],
        "license": "MIT",
        "type": "project",
        "require": {
            "php": ">=7.0.0",
            "fideloper/proxy": "~3.3",
            "laravel/framework": "5.7.*",
            "laravel/tinker": "~1.0",
            "tymon/jwt-auth": "^0.5.12"
        },
        "require-dev": {
            "filp/whoops": "~2.0",
            "fzaninotto/faker": "~1.4",
            "mockery/mockery": "~1.0",
            "phpunit/phpunit": "~6.0",
            "symfony/thanks": "^1.0"
        },
        "autoload": {
            "classmap": [
                "database/seeds",
                "database/factories"
            ],
            "psr-4": {
                "App\\": "app/"
            }
        },
        "autoload-dev": {
            "psr-4": {
                "Tests\\": "tests/"
            }
        },
        "extra": {
            "laravel": {
                "dont-discover": [
                ]
            }
        },
        "scripts": {
            "post-root-package-install": [
                "@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
            ],
            "post-create-project-cmd": [
                "@php artisan key:generate"
            ],
            "post-autoload-dump": [
                "Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
                "@php artisan package:discover"
            ]
        },
        "config": {
            "preferred-install": "dist",
            "sort-packages": true,
            "optimize-autoloader": true
        } }
    

    I am still handling the same error. Can you guys figure it out where the problem is ?

  • alphal
    alphal over 5 years
    Yes but the same problem
  • Miloslav Milo Janoušek
    Miloslav Milo Janoušek almost 4 years
    For me this didn't help.
  • iHabboush
    iHabboush almost 4 years
    @MiloslavMiloJanoušek, did you get the same error message?
  • Altin
    Altin about 3 years
    2) fixed it for me (I had $headers as array, from previous versions). Thank you!
  • Jsowa
    Jsowa about 2 years