mirror of
https://github.com/php-flasher/php-flasher.git
synced 2026-03-31 15:07:47 +01:00
359e6de361
Each adapter README now includes: - Features section highlighting key capabilities - Installation instructions for Laravel and Symfony - Multiple Quick Start code examples - Configuration options table - Livewire integration with events - Global configuration examples
4.4 KiB
4.4 KiB
PHPFlasher SweetAlert Adapter
Beautiful, responsive, customizable alerts using SweetAlert2 for PHPFlasher.
Features
- Confirmation dialogs with Confirm/Deny/Cancel buttons
- User input dialogs (text, email, password, select, etc.)
- Custom HTML content support
- Image and icon customization
- Toast mode for non-blocking notifications
- Timer-based auto-close
Installation
Laravel:
composer require php-flasher/flasher-sweetalert-laravel
php artisan flasher:install
Symfony:
composer require php-flasher/flasher-sweetalert-symfony
php bin/console flasher:install
Quick Start
// Using the helper function
sweetalert()->success('Profile updated successfully!');
// With a title
sweetalert()->info('Please read the terms before continuing', 'Important');
// Error notification
sweetalert()->error('Unable to process your request.');
// Toast mode (non-blocking)
sweetalert()->success('Saved!', [
'toast' => true,
'position' => 'top-end',
'timer' => 3000,
]);
// Auto-close with timer
sweetalert()->info('Redirecting...', ['timer' => 2000]);
Confirmation Dialogs
// Simple confirmation
sweetalert()
->showDenyButton()
->success('Do you want to save the changes?');
// With all three buttons
sweetalert()
->showDenyButton(true, 'Don\'t save')
->showCancelButton(true, 'Cancel')
->warning('Do you want to save the changes?');
// Delete confirmation
sweetalert()
->showCancelButton()
->confirmButtonColor('#d33')
->warning('Are you sure you want to delete this item?', 'This action cannot be undone');
Configuration Options
| Option | Type | Default | Description |
|---|---|---|---|
toast |
bool | false |
Enable toast mode (corner notification) |
position |
string | center |
Dialog position on screen |
timer |
int | null |
Auto-close delay in ms |
timerProgressBar |
bool | false |
Show progress bar for timer |
showConfirmButton |
bool | true |
Show confirm button |
showDenyButton |
bool | false |
Show deny button |
showCancelButton |
bool | false |
Show cancel button |
confirmButtonText |
string | OK |
Confirm button text |
denyButtonText |
string | No |
Deny button text |
cancelButtonText |
string | Cancel |
Cancel button text |
Position Options
top,top-start,top-endcenter,center-start,center-endbottom,bottom-start,bottom-end
Livewire Integration
SweetAlert works seamlessly with Livewire. You can listen to button click events:
use Livewire\Attributes\On;
#[On('sweetalert:confirmed')]
public function onConfirmed(array $payload): void
{
// User clicked confirm button
$this->performAction();
}
#[On('sweetalert:denied')]
public function onDenied(array $payload): void
{
// User clicked deny button
}
#[On('sweetalert:dismissed')]
public function onDismissed(array $payload): void
{
// User dismissed the dialog (clicked cancel or outside)
}
Available Events
| Event | Description |
|---|---|
sweetalert:confirmed |
Fired when confirm button is clicked |
sweetalert:denied |
Fired when deny button is clicked |
sweetalert:dismissed |
Fired when dialog is dismissed |
Global Configuration
Laravel (config/flasher.php):
'plugins' => [
'sweetalert' => [
'options' => [
'position' => 'center',
'timer' => null,
'showConfirmButton' => true,
'timerProgressBar' => true,
],
],
],
Symfony (config/packages/flasher.yaml):
flasher:
plugins:
sweetalert:
options:
position: center
timer: null
showConfirmButton: true
timerProgressBar: true
Documentation
For complete documentation, visit php-flasher.io/library/sweetalert.