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

Ajvanho's avatar
Level 14

Livewire session?

Can I use LW Flash Messages when I dont create or save records in db? For example, in this case it does not appear to me:

public function deleteStation()
    {
        $station = Station::find($this->deleteId);
        if ( $station->lines()->exists() ) {
            session()->flash('station_forbidden', 'Sorry, this station have line');
            $this->showDeleteModal = false;
        } else {
            Station::destroy($this->deleteId);
            $this->showDeleteModal = false; 
        }
    }

0 likes
3 replies
tykus's avatar

I believe you must check for the presence of the station_forbidden session key within the Livewire component; the entire DOM does not re-render, only the component itself. Do you attempt to display the flash message outside the component's template?

1 like
Ajvanho's avatar
Level 14

I did it differently, without session. I created a variable with a message.

tykus's avatar

Similarly, I have not used the session in my projects either; it doesn't make a lot of sense if my reasoning above is correct about the placement of the session check.

I have a Toast component in my layout template which listens for a notify event emitting from any Livewire component; whenever a notify event is emitted from anywhere in the Livewire parts of my app, a notification toast will display the message.

1 like

Please or to participate in this conversation.