Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

mzprog's avatar
Level 1

Laravel 11 - Facade in bootstrap/app.php

I need to use cache in app.php using this code:

$res = Cache::remember('cloudflareips', 24 * 3600, function () {
    return Http::get($url)->json('result');
});

if ($res && isset($res['ipv4_cidrs'])) {
       $middleware->trustProxies(at: $res['ipv4_cidrs']);
}

I got an error Fatal error: Uncaught RuntimeException: A facade root has not been set. in /home/user/Projects/example-web/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php:354

what can i do to solve it?

0 likes
1 reply
MichalOravec's avatar

You can use TrustProxies::at($at) directly in you AppServiceProvider:

use use Illuminate\Http\Middleware\TrustProxies;

public function boot()
{
    $res = Cache::remember('cloudflareips', 24 * 3600, function () {
        return Http::get($url)->json('result');
    });

    if ($res && isset($res['ipv4_cidrs'])) {
        TrustProxies::at($res['ipv4_cidrs']));
    }
}
1 like

Please or to participate in this conversation.