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

vk011's avatar
Level 1

Sharing session data accross views

How to share session data accross views?

Say I have a session key with some data, in a controller I'd get it like so:

$session = $request->session()->get('someSessionValue');

And then pass it on to the view, fair enough.

And if I wanted to share some non session data accross all views, in AppServiceProvider I'd do e.g.:

public function boot()
    {
        $logo = \App\Misc::where('name', 'logo')->value('content');

        View::share('logo', $logo);

    }

But I cannot do that with session data, is it possible?

0 likes
1 reply
ftiersch's avatar
ftiersch
Best Answer
Level 28

You can access the session directly inside your view with

session()->get('something')

It's a global helper and works there too.

1 like

Please or to participate in this conversation.