Add Laravel broadcasting support (Reverb, Pusher, Ably)#23
Conversation
Agent-Logs-Url: https://github.com/sweetalert2/sweetalert2-laravel/sessions/f9df8f3f-a4aa-412e-a625-03ee327206c0 Co-authored-by: limonte <6059356+limonte@users.noreply.github.com>
…hods directly Agent-Logs-Url: https://github.com/sweetalert2/sweetalert2-laravel/sessions/f9df8f3f-a4aa-412e-a625-03ee327206c0 Co-authored-by: limonte <6059356+limonte@users.noreply.github.com>
|
@copilot tests are failing |
…atisfy strict return type Agent-Logs-Url: https://github.com/sweetalert2/sweetalert2-laravel/sessions/cc463190-b66e-46f8-a760-0678c5e1c076 Co-authored-by: limonte <6059356+limonte@users.noreply.github.com>
Fixed in a2559ab. The recording broadcaster stub's |
|
@copilot 2 tests are still failing: |
…od appears in rendered output Agent-Logs-Url: https://github.com/sweetalert2/sweetalert2-laravel/sessions/f85925ac-bc0c-43b7-9dd0-e35e2750ef39 Co-authored-by: limonte <6059356+limonte@users.noreply.github.com>
... Fixed in fa5e476. The blade template was using a JS ternary, so both |
|
@SlothLady WDYT about this? |
There was a problem hiding this comment.
Pull request overview
Adds real-time SweetAlert2 notifications via Laravel’s broadcasting system, enabling backend-triggered popups/toasts to appear in the browser without a page reload (public and private channels) while matching the existing session/livewire/inertia rendering + callback handling approach.
Changes:
- Introduces
SweetAlert2BroadcastEvent(ShouldBroadcastNow) and asweetalert2::broadcastBlade partial that subscribes via Laravel Echo and callsSwal.fire()on incoming events. - Extends
Swalwithbroadcast*()andbroadcastPrivate*()helper methods mirroring the existing icon/toast shortcut API. - Adds comprehensive tests for the event, Blade partial rendering, and
Swalbroadcasting helpers; documents setup/usage in the README and updates Composer suggestions.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| tests/BroadcastTest.php | Adds tests covering the broadcast event, listener view, and Swal::broadcast*() helper behavior. |
| src/Swal.php | Adds public/private broadcasting helper methods for popups and toasts. |
| src/ServiceProvider.php | Registers resources/views/shared under the sweetalert2 namespace to expose the broadcast partial. |
| src/Events/SweetAlert2BroadcastEvent.php | New ShouldBroadcastNow event defining channel, event name, and payload. |
| resources/views/shared/broadcast.blade.php | New Echo listener partial that loads SweetAlert2 (if needed) and safely parses callback options. |
| README.md | Documents broadcasting setup and usage for public/private channels plus helper method lists. |
| composer.json | Suggests laravel/reverb (or another broadcaster) for using the broadcasting feature. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Real-time SweetAlert2 popups from the backend without a page reload — useful for actions like sending emails from a dashboard, completing background jobs, or any server-side event that shouldn't navigate the user.
Backend
New static methods on
Swaldispatch aSweetAlert2BroadcastEvent(ShouldBroadcastNow) via Laravel's broadcasting system:Full set of icon/toast shortcuts mirrors the existing
Swal::fire()/Swal::success()/Swal::toastSuccess()API for both public and private channels.Frontend
A new blade partial subscribes to the channel via Laravel Echo and fires
Swal.fire()on receipt. Uses the same callback validation + XSS sanitisation as the existing Livewire/Inertia templates.Key implementation details
SweetAlert2BroadcastEventimplementsShouldBroadcastNow(sync, no queue required); broadcasts assweetalert2-message— the existingSESSION_KEYconstant — so Echo listens with.sweetalert2-messageresources/views/shared/is registered as a secondary view path under thesweetalert2namespace, sosweetalert2::broadcastresolves whilesweetalert2::indexcontinues to resolve from the context-specific path (livewire/inertia/laravel)Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
https://api.github.com/repos/doctrine/inflector/zipball/6d6c96277ea252fc1304627204c3d5e6e15faa3b/usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/jZph7v /usr/bin/composer global require laravel/installer(http block)https://api.github.com/repos/illuminate/collections/zipball/17b082d0c66fb030f22d5bdd62ba652c045ff522REDACTED, pid is -1(http block)https://api.github.com/repos/illuminate/conditionable/zipball/7f1ef52d9a346f829421b296adfb7644a951b216/usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/jZph7v /usr/bin/composer global require laravel/installer(http block)https://api.github.com/repos/illuminate/contracts/zipball/ce6f5561f88743639c76835ad82cfe39b468bdc8/usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/jZph7v /usr/bin/composer global require laravel/installer(http block)https://api.github.com/repos/illuminate/macroable/zipball/59b5b5f3cf290a91db8cf6cd3d35ff56978bc057/usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/jZph7v /usr/bin/composer global require laravel/installer(http block)https://api.github.com/repos/illuminate/reflection/zipball/4fe1659f068ab2b50131cf906c5d8bba4e34df0cREDACTED, pid is -1(http block)https://api.github.com/repos/php-fig/container/zipball/c71ecc56dfe541dbd90c5360474fbc405f8d5963/usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/jZph7v /usr/bin/composer global require laravel/installer(http block)https://api.github.com/repos/php-fig/simple-cache/zipball/764e0b3939f5ca87cb904f570ef9be2d78a07865/usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/jZph7v /usr/bin/composer global require laravel/installer(http block)https://api.github.com/repos/symfony/polyfill-php84/zipball/88486db2c389b290bf87ff1de7ebc1e13e42bb06REDACTED, pid is -1(http block)https://api.github.com/repos/symfony/polyfill-php85/zipball/fcfa4973a9917cef23f2e38774da74a2b7d115ee/usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/jZph7v /usr/bin/composer global require laravel/installer(http block)https://api.github.com/repos/symfony/polyfill-php86/zipball/33d8fc5a705481e21fe3a81212b26f9b1f61749c/usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/jZph7v /usr/bin/composer global require laravel/installer(http block)https://api.github.com/repos/symfony/process/zipball/60f19cd3badc8de688421e21e4305eba50f8089aREDACTED, pid is -1(http block)If you need me to access, download, or install something from one of these locations, you can either: