Effortlessly Trigger Modals with Session Flash in Laravel

1 min read

Here’s a dead simple way of triggering a model to show or anything really from a controller.
From a controller after using session()→flash()
to setup a session value
session()->flash('show-update-current-orders-dialog');
Then in a blade file, check for a session matching this value:
@session('show-update-orders-dialog')
<x-update-order-dialog/>
@endsession
This way you can trigger a model when there is a matching session, this is one time. Once the session has been used if won’t render a second time.
This is incredibly simple but a powerful technique that does not require events or listeners.
0
Subscribe to my newsletter
Read articles from David Carr directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

David Carr
David Carr
Blogger at http://dcblog.dev.