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

sooluh's avatar
Level 1

Sharing data with all views in Provider but with Octane, it doesn't work

As written in the documentation in the View section that we can share data to all views with View::blade and placed in the boot method on the AppServiceProvider. But on the other hand, in the documentation in the Octane section it is explained that the register and boot methods on each provider are only called once when the request worker initially boots. Is there another way to share data to all views with View::blade that works correctly with Laravel Octane?

0 likes
1 reply
sooluh's avatar
sooluh
OP
Best Answer
Level 1

Solved! I previously used the following code

public function boot(): void
{
    View::share('key', 'value');
}

and now I use the following code

public function boot(): void
{
    View::composer('*', function($view) {
        $view->with('key', 'value');
    });
}

Please or to participate in this conversation.