## Getting Started
### Minimal Setup
1. **Install via Composer**:
```bash
composer require islamalsayed/laravel-toasts
php artisan vendor:publish --provider="IslamAlsayed\LaravelToasts\LaravelToastsServiceProvider" --tag="toasts-assets"
php artisan vendor:publish --provider="IslamAlsayed\LaravelToasts\LaravelToastsServiceProvider" --tag="toasts-config"
@toastsScripts
Blade Template:
@toast('Success!', 'Your action was completed.', 'success')
Livewire Component:
use IslamAlsayed\LaravelToasts\Facades\Toast;
public function save()
{
// ...
Toast::success('Success!', 'Your action was completed.');
}
Blade Macro:
@toast('Title', 'Message', 'type', ['position' => 'top-right'])
Types: success, error, danger, warning, info.
Facade Usage:
Toast::info('Info Title', 'Info message', ['duration' => 5000]);
@toast('Message-only content', null, 'warning', ['mode' => 'message-only'])
Toast::warning('Message-only content', null, ['mode' => 'message-only']);
Dispatching from Livewire:
use IslamAlsayed\LaravelToasts\Facades\Toast;
public function deleteItem()
{
// ...
Toast::dispatch('Item deleted', 'The item was removed successfully.', 'success');
}
Listening in Livewire:
protected $listeners = ['toast' => 'handleToast'];
public function handleToast($message, $title, $type)
{
Toast::make($title, $message, $type);
}
@confirm('Delete Item?', 'Are you sure you want to delete this item?', 'deleteItem')
Toast::confirm('Delete?', 'This action cannot be undone.', 'deleteItem');
@toast('Custom Icon', 'Message with 🚀 emoji.', 'success', ['icon' => '🚀'])
Toast::success('Custom Icon', 'Message with <i class="fas fa-rocket"></i> icon.', [
'icon' => '<i class="fas fa-rocket"></i>'
]);
Toast::info('Important Notice', 'This will not auto-dismiss.', ['pinned' => true]);
Toast::success('Action Required', 'Click to retry.', [
'actions' => [
['text' => 'Retry', 'callback' => 'retryAction']
]
]);
// Trigger from JS
LaravelToast.success('JS Toast', 'Triggered via JavaScript API.');
// Listen for events
document.addEventListener('toast:show', (e) => {
console.log('Toast shown:', e.detail);
});
@toast and @confirm in Blade templates for quick, declarative notifications.['position' => 'bottom-left', 'duration' => 3000]).Toast::dispatch() for cross-component communication.php artisan vendor:publish --tag="toasts-assets"
resources/css/toasts.css and recompile assets if needed.{{ __('messages.key') }} or similar for translation.php artisan vendor:publish --tag="toasts-config"
default_duration, positions, or icons.Livewire Event Conflicts:
Toast::dispatch(), ensure the event name (toast) doesn’t conflict with other Livewire events.Toast::dispatch('my-app.toast');
Asset Loading Issues:
@toastsScripts is included in your layout.<script src="{{ asset('vendor/laravel-toasts/js/toasts.js') }}"></script>
RTL Styling Glitches:
direction: rtl is applied to the correct elements.Pinned Toast Z-Index:
z-index in the published CSS:
.toast.pinned {
z-index: 99999 !important;
}
Livewire Hydration Conflicts:
wire:ignore on the toast container or trigger toasts after hydration:
protected $listeners = ['toast' => 'handleToast' => self::ignoreSelf()];
public function mount()
{
$this->dispatch('toast', data: ['title' => 'Mounted', 'message' => 'Ready.']);
}
Check Console for Errors:
F12) and look for JS errors related to LaravelToast.Verify Toast Events:
toast:show events in JS to debug payloads:
document.addEventListener('toast:show', (e) => console.log(e.detail));
Inspect Network Requests:
laravel-toasts in the Network tab).Test in Isolation:
@toast('Test', 'Is this working?', 'success')
Dynamic Toast Content:
@toast("{{ $user->name }}", 'Profile updated successfully.', 'success')
Conditional Toasts:
if ($this->success) {
Toast::success('Operation completed', 'Check your inbox.');
}
Custom Toast Templates:
php artisan vendor:publish --tag="toasts-views"
resources/views/vendor/toasts/toast.blade.php.Localization:
@toast(__('toasts.success.title'), __('toasts.success.message'), 'success')
Performance:
Toast::queue('New message', 'Content here.', 'info');
Dark Mode Support:
.dark classes:
.dark .toast {
background-color: #333;
color: #fff;
}
Accessibility:
role="alert" to the toast container:
<div class="toast" role="alert" aria-live="assertive">
Testing:
How can I help you explore Laravel packages today?