49

Nothing to install, update or remove Generating optimized autoload files Class App\Helpers\Helper located in C:/wamp64/www/vuexylaravel/app\Helpers\helpers.php does not comply with psr-4 autoloading standard. Skipping. > Illuminate\Foundation\ComposerScripts::postAutoloadDump > @php artisan package:discover --ansi

   Error 

  Undefined constant Illuminate\Http\Request::HEADER_X_FORWARDED_ALL
  at C:\wamp64\www\vuexylaravel\vendor\fideloper\proxy\config\trustedproxy.php:48
     44▕      * - 'HEADER_X_FORWARDED_AWS_ELB' (If you are using AWS Elastic Load Balancer)
     45▕      *
     46▕      * @link https://symfony.com/doc/current/deployment/proxies.html
     47▕      */
  ➜  48▕     'headers' => Illuminate\Http\Request::HEADER_X_FORWARDED_ALL,
     49▕
     50▕ ];
     51▕

  1   C:\wamp64\www\vuexylaravel\vendor\laravel\framework\src\Illuminate\Support\ServiceProvider.php:138
      require()

  2   C:\wamp64\www\vuexylaravel\vendor\fideloper\proxy\src\TrustedProxyServiceProvider.php:28
      Illuminate\Support\ServiceProvider::mergeConfigFrom("C:\wamp64\www\vuexylaravel\vendor\fideloper\proxy\config\trustedproxy.php", "trustedproxy")
Script @php artisan package:discover --ansi handling the post-autoload-dump event returned with error code 1
Sajeed Kannoje
  • 931
  • 1
  • 5
  • 13

7 Answers7

88

The colleague with the answer above is, in principle, right. Only he forgot to mention that after all the changes in the file, you need to delete the package fideloper/proxy:

https://laravel.com/docs/9.x/upgrade

Trusted Proxies

Likelihood Of Impact: Low

If you are upgrading your Laravel 8 project to Laravel 9 by importing your existing application code into a totally new Laravel 9 application skeleton, you may need to update your application's "trusted proxy" middleware.

Within your app/Http/Middleware/TrustProxies.php file, update use Fideloper\Proxy\TrustProxies as Middleware to use Illuminate\Http\Middleware\TrustProxies as Middleware.

Next, within app/Http/Middleware/TrustProxies.php, you should update the $headers property definition:

// 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;

Finally, you can remove the fideloper/proxy Composer dependency from your application:

composer remove fideloper/proxy

Николай
  • 1,003
  • 1
  • 6
  • 9
  • 5
    Thx alot but right after that i got `Target class [Fruitcake\Cors\HandleCors] does not exist.` sorry i just had to remove `\Fruitcake\Cors\HandleCors::class,` from app/Http/Kernel.php : ` protected $middleware = [ – Vipertecpro Feb 25 '22 at 18:03
  • @Николай Thanks alot. That spot on was the issue for me. – Daniel Böttner May 22 '22 at 19:49
  • I also had to remove the file config/trustedproxy.php in my own case – user28864 Aug 04 '23 at 09:16
41

If you are upgrading your Laravel 8 project to Laravel 9 by importing your existing application code into a totally new Laravel 9 application skeleton, you may need to update your application's "trusted proxy" middleware.

Within your app/Http/Middleware/TrustProxies.php file, update:

use Fideloper\Proxy\TrustProxies as Middleware

to

use Illuminate\Http\Middleware\TrustProxies as Middleware

Next, within app/Http/Middleware/TrustProxies.php, you should update the $headers property definition:

// 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;

Then run composer update

Make sure you are using PHP 8.0

pableiros
  • 14,932
  • 12
  • 99
  • 105
Sajeed Kannoje
  • 931
  • 1
  • 5
  • 13
7

If the above answer does not work for you and you are getting the same error, execute one more line for removing the fideloper/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 fideloper/proxy

it's properly mentioned in the laravel 9 upgrade guide. https://laravel.com/docs/9.x/upgrade#the-assert-deleted-method

Hadayat Niazi
  • 1,991
  • 3
  • 16
  • 28
  • when i run ```composer remove fideloper/proxy``` , get this new bug: **Undefined array key "format"** , do you know how to fix it ? – Azade May 15 '22 at 09:57
  • Thanks. It's worked. The approved answer didn't help, cause I have no TrustProxies.php. I don't know why, I just didn't have that middleware. – Ruben Kubalyan May 20 '22 at 07:34
1

If you are upgrading your Laravel 8 project to Laravel 9 by importing your existing application code into a totally new Laravel 9 application skeleton, I tried this solution below.

a) I fixed it by deleting "config/trustedproxy.php". I did not have the TrustProxies middleware on the directory at app\Http\Middleware on my side

  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Apr 29 '22 at 12:47
  • No sure why I had this file too (can't find it on official github repo), but deleting it solved my problem. Thx ! – rou6e May 06 '22 at 15:53
  • It's right here https://github.com/laravel/laravel/blob/9.x/app/Http/Middleware/TrustProxies.php – Emil Moe May 23 '22 at 10:50
1

If you are upgrading your Laravel 8 project to Laravel 9 by importing your existing application code into a totally new Laravel 9 application skeleton, you may need to update your application's "trusted proxy" middleware.

Within your app/Http/Middleware/TrustProxies.php file, update use Fideloper\Proxy\TrustProxies as Middleware to use Illuminate\Http\Middleware\TrustProxies as Middleware.

Next, within app/Http/Middleware/TrustProxies.php, you should update the $headers property definition:

// 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;

Finally, you can remove the fideloper/proxy Composer dependency from your application:

composer remove fideloper/proxy

1

Basically all above anwser are telling the same thing, Laravel docs are correct, simply follow instructions.

But is you still have the same error (like I did), delete file "config/trustedproxy.php". This fixs the error.

crisleiria
  • 51
  • 1
  • 7
  • Was still getting the same error after laravel docs, but removed "config/trustedproxy.php" fixes the error – ottz0 Dec 19 '22 at 03:10
0

Two things I did after following the laravel upgrade doc which worked for me:

  1. Manually go into composer.json and remove the fideloper/proxy

Run composer update. If you still get the issue. Follow next:

  1. Check if this file TrustProxies.php is present located at vendor\laravel\framework\src\Illuminate\Http\Middleware\TrustProxies.php if Not you can copy from old one.
Prosper
  • 19
  • 1