Error: While updating laravel 8 to 9. Script @php artisan package:discover --ansi handling the post-autoload-dump event returned with error code 1
Asked Answered
S

8

52

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
Surrounding answered 13/2, 2022 at 17:35 Comment(0)
S
44

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

Surrounding answered 13/2, 2022 at 17:35 Comment(1)
I also had to remove the file config/trustedproxy.php in my own caseLeonie
D
97

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

Dasteel answered 14/2, 2022 at 19:39 Comment(3)
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 = [Sandalwood
@Dasteel Thanks alot. That spot on was the issue for me.Disengagement
I also had to remove the file config/trustedproxy.php in my own caseLeonie
S
44

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

Surrounding answered 13/2, 2022 at 17:35 Comment(1)
I also had to remove the file config/trustedproxy.php in my own caseLeonie
M
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

Madelainemadeleine answered 29/3, 2022 at 6:51 Comment(2)
when i run composer remove fideloper/proxy , get this new bug: Undefined array key "format" , do you know how to fix it ?Stultify
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.Folacin
P
2

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

Pinhole answered 6/9, 2022 at 18:16 Comment(0)
N
2

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.

Nonobservance answered 19/9, 2022 at 10:6 Comment(1)
Was still getting the same error after laravel docs, but removed "config/trustedproxy.php" fixes the errorGrillroom
G
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

Gunslinger answered 29/4, 2022 at 8:50 Comment(3)
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.Mukden
No sure why I had this file too (can't find it on official github repo), but deleting it solved my problem. Thx !Furl
It's right here github.com/laravel/laravel/blob/9.x/app/Http/Middleware/…Palindrome
M
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.
Mozellemozes answered 12/4, 2022 at 7:38 Comment(0)
T
-1

you need to delete file "config/trustedproxy.php"

After run composer update

Tew answered 24/11, 2023 at 6:46 Comment(1)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Mukden

© 2022 - 2025 — McMap. All rights reserved.