Search code examples
laravelsession-statelaravel-livewire

Save data to sessions long term in Laravel Livewire?


I have a social network and want to store user interests likes/dislikes in a session since there are many subpages where I need this data and I want to avoid querying the database for that on every page. However, it seems you can only save flash data in sessions in Livewire.

The usual Laravel $request->session()->put(...) feature to save data long term in sessions doesn't seem to work in Livewire? So how could I save data long term in sessions or is there an other option or feature?


Solution

  • So, I just found out the answer by myself.

    You can actually just use session()->put('key', 'value').

    I wonder why this isn't officially documented tho. Maybe this helps someone of you too.