Skip to content

Instantly share code, notes, and snippets.

@RikoDEV
Last active August 24, 2023 09:28
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RikoDEV/7ec6feaee359bcf8ee8c2c6f78d8951a to your computer and use it in GitHub Desktop.
Save RikoDEV/7ec6feaee359bcf8ee8c2c6f78d8951a to your computer and use it in GitHub Desktop.
Trigger Laravel Jetstream banner from Livewire component
// Success banner
$this->dispatchBrowserEvent('banner-message', [
'style' => 'success',
'message' => 'Amazing success banner!'
]);
// Danger banner
$this->dispatchBrowserEvent('banner-message', [
'style' => 'danger',
'message' => 'Mysterious danger banner!'
]);
@Kenny1291
Copy link

💝

@nexxai
Copy link

nexxai commented Mar 24, 2023

Holy crap thank you

@iammuttaqi
Copy link

Thanks!

@dakira
Copy link

dakira commented Mar 29, 2023

@RikoDEV @iammuttaqi
If you're using Jetstream, you can use the Laravel\Jetstream\InteractsWithBanner trait in your Livewire component and just call banner($message) or dangerBanner($message).

How I know? I implemented it using your snippet and when I wanted to import the trait I wrote, two traits showed up, the one I wrote and the one that already comes with Jetstream. :-)

@GavG
Copy link

GavG commented Aug 24, 2023

Laravel\Jetstream\InteractsWithBanner

Legend!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment