Having trouble getting a property in the TrustedProxy.php middleware from config.
The default is:
<?php
namespace App\Http\Middleware;
use Fideloper\Proxy\TrustProxies as Middleware;
use Illuminate\Http\Request;
class TrustProxies extends Middleware
{
/**
* The trusted proxies for this application.
*
* @var array|string|null
*/
protected $proxies;
/**
* The headers that should be used to detect proxies.
*
* @var int
*/
protected $headers = Request::HEADER_X_FORWARDED_ALL;
}
We want to get $proxies from config('network.trusted_proxies'). Our config/network.php looks like:
'trusted_proxies' => explode(',', env('NETWORK_TRUSTED_PROXIES', null)),
The first thing I tried in the middleware was:
protected $proxies = config('network.trusted_proxies');
However, this throws exception "Constant expression contains invalid operations".
So I removed that line and added:
public function proxies()
{
return config('network.trusted_proxies');
}
While this resolves the exception, it is not working as intended because the middleware is seeing $proxies as an empty value.
Everything works exactly as expected with our proxies when I define the property like so:
protected $proxies = "*";
I'm surely doing something wrong in my attempts to pull the value from config.
Is what I'm trying to do even possible? Our goal here is to be able to manage trusted proxy config from .env rather than having to update the codebase each time a proxy is added or removed.
Any help greatly appreciated.