RSS Amplifier

David Carr's Blog · Jan 14, 2025

Effortlessly Trigger Modals with Session Flash in Laravel

0
Sign in to vote or save

dcblog.dev

Here’s a dead simple way of triggering a model to show or anything really from a controller.

From a controller use session()→flash() to setup a session value

session()->flash('show-update-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.

Subscribe to my newsletter for the latest updates on my books and digital products.

Read the original on dcblog.dev

Comments

Nothing yet. Say the first thing.

    Sign in to join the conversation.