composer require twiq/livewire-notify
npm install --save-dev @twiq/laravel-notifications # If frontend assets are needed
php artisan vendor:publish --provider="Twiq\LivewireNotify\LivewireNotifyServiceProvider" --tag="config"
php artisan vendor:publish --provider="Twiq\LivewireNotify\LivewireNotifyServiceProvider" --tag="public"
resources/views/layouts/app.blade.php):
<livewire:livewire-notify />
use Twiq\LivewireNotify\Facades\LivewireNotify;
public function save()
{
LivewireNotify::success('Item saved successfully!');
}
Display a success notification after a form submission:
public function submitForm()
{
$this->validate([...]);
// Business logic...
LivewireNotify::success('Your changes have been saved!');
return redirect()->to('/dashboard');
}
Triggering Notifications: Use facade methods in Livewire actions:
LivewireNotify::error('Invalid input', ['title' => 'Validation Error']);
LivewireNotify::warning('Session expired', ['timeout' => 10]);
Conditional Notifications:
if ($this->save()) {
LivewireNotify::success('Success!', ['group' => 'user-actions']);
} else {
LivewireNotify::error('Failed to save.', ['group' => 'user-actions']);
}
Grouped Notifications:
// Show multiple notifications in a group
LivewireNotify::info('First message', ['group' => 'updates']);
LivewireNotify::info('Second message', ['group' => 'updates']);
Persistent Notifications:
LivewireNotify::error('Critical error', ['persistent' => true]);
event(new \Twiq\LivewireNotify\Events\NotifyEvent('Custom message'));
resources/js/app.js:
document.addEventListener('alpine:init', () => {
Alpine.data('customNotify', () => ({
init() {
this.$watch('open', (value) => {
if (value) this.playSound();
});
},
playSound() { /* ... */ }
}));
});
resources/css/app.css:
.notify-success { @apply bg-emerald-500; }
Duplicate Notifications:
group parameter or adjust duplicateThreshold in config:
LivewireNotify::success('Message', ['group' => 'unique-group']);
'duplicate_threshold' => 2, // seconds
Livewire Component Not Rendering:
<livewire:livewire-notify /> is in a parent component (not a modal/dialog).LivewireNotifyServiceProvider is registered in config/app.php.Tailwind Conflicts:
npx tailwindcss -i ./resources/css/app.css -o ./public/css/app.css --watch
Alpine.js Initialization:
<script src="https://cdn.jsdelivr.net/npm/alpinejs@3.x.x/dist/cdn.min.js" defer></script>
Log Notifications: Enable debug mode in config:
'debug' => env('APP_DEBUG', false),
Check Laravel logs for triggered notifications.
Inspect DOM: Use browser dev tools to verify the notification container exists:
<div x-data="livewireNotify()" x-init="init()" class="fixed top-4 right-4 z-50">
Custom Notification Types:
Extend the Notification class:
namespace App\Notifications;
use Twiq\LivewireNotify\Notification;
class CustomNotification extends Notification
{
public $type = 'custom';
public $icon = '✨';
}
Use via facade:
LivewireNotify::custom(new CustomNotification('Hello!'));
Override Default Views: Publish and modify views:
php artisan vendor:publish --tag="livewire-notify-views"
Edit resources/views/vendor/livewire-notify/.
Sound Configuration:
Customize sounds in config/livewire-notify.php:
'sounds' => [
'success' => 'https://example.com/success.mp3',
'error' => asset('sounds/error.mp3'),
],
Dark Mode Quirks: Force dark mode in config:
'dark_mode' => 'media', // 'media', 'light', or 'dark'
How can I help you explore Laravel packages today?