Have you upgraded your Laravel application to Laravel 9 and received the “Undefined Constant llluminate\Http\Request::HEADER_X_FORWARDED_ALL” error when running composer update?
It’s easy to miss on the official Laravel upgrade guide. The Laravel team state the likelihood of impact for this error is low, and thankfully it’s a quick and easy fix.
In this post you will understand what has changed under the hood of Laravel and its dependencies. You will learn how to fix the error “Undefined Constant llluminate\Http\Request::HEADER_X_FORWARDED_ALL” when running composer update.
What’s changed in Laravel 9?
The change comes from the Symfony HttpFoundation component used by Laravel. Laravel previously used HEADER_X_FORWARDED_ALL constant for the value of the $headers property in the TrustProxies.php file, however since Symfony 5.2 this was deprecated, and finally removed in version 6.0.
When upgrading to Laravel 9, composer upgrades dependencies aswell. When the Symfony HttpFoundation package is upgraded, the Undefined Constant llluminate\Http\Request::HEADER_X_FORWARDED_ALL error is thrown.
Solution to fix the Laravel 9 Undefined Constant error
Follow the steps below to fix the Undefined constant Illuminate\Http\Request::HEADER_X_FORWARDED_ALL error.
Within your app open /Http/Middleware/TrustProxies.php and update line 5.
Use Fideloper\Proxy\TrustProxies as Middle;
Change this line to:
Use Illuminate\Http\Middleware\TrustProxies as Middleware;
Next, you need to update the $headers property.
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;
And finally, you can remove fideloper/proxy composer dependency from your application:
composer remove fideloper/proxy
You can read more about the changes required when upgrading to Laravel 9 in the official upgrade guide under the Trusted Proxies subheading.