Installation:
composer require caiquebispo/notification-bell
Publish the package assets and config:
php artisan vendor:publish --provider="CaiqueBispo\NotificationBell\NotificationBellServiceProvider" --tag="public"
php artisan vendor:publish --provider="CaiqueBispo\NotificationBell\NotificationBellServiceProvider" --tag="config"
Run migrations:
php artisan migrate
Add the trait to your User model:
use CaiqueBispo\NotificationBell\Traits\HasNotifications;
class User extends Authenticatable
{
use HasNotifications;
// ...
}
Include the Livewire component in your layout:
@livewire('notification-bell::bell')
Trigger your first notification (e.g., in a controller):
use CaiqueBispo\NotificationBell\Facades\NotificationBell;
NotificationBell::success('Your notification title', 'Notification body content');
// In a controller or service
NotificationBell::success('Profile Updated', 'Your profile has been successfully updated.');
text-green-500).Use the NotificationBell facade or helper class in controllers/services:
// Basic types
NotificationBell::success('Title', 'Body');
NotificationBell::error('Title', 'Body');
NotificationBell::warning('Title', 'Body');
NotificationBell::info('Title', 'Body');
// With custom icon (Tailwind class)
NotificationBell::custom('Title', 'Body', 'fas fa-bell-slash');
// With actions (e.g., "View" button)
NotificationBell::success('Title', 'Body')
->action('View', route('notifications.show'), 'primary');
notification-bell::bell component auto-renders in your layout.'position' => 'top-right', // 'top-left', 'bottom-left', 'bottom-right'
'autoDismiss' => false,
NotificationBell::success('Title', 'Body')->sync();
php artisan queue:work
HasNotifications trait.public function getNotificationsProperty()
{
return auth()->user()->unreadNotifications;
}
dark: variants).tailwind.config.js:
module.exports = {
darkMode: 'class',
theme: {
extend: {
colors: {
bell: {
DEFAULT: '#3b82f6',
dark: '#60a5fa',
},
},
},
},
};
Extend the Livewire component by publishing and overriding views:
php artisan vendor:publish --tag="notification-bell-views"
Modify:
resources/views/vendor/notification-bell/bell.blade.php (main dropdown)resources/views/vendor/notification-bell/notification.blade.php (individual notification)Create a helper method in app/Helpers/NotificationHelper.php:
use CaiqueBispo\NotificationBell\Facades\NotificationBell;
if (!function_exists('customNotification')) {
function customNotification($title, $body, $icon = 'fas fa-robot')
{
return NotificationBell::custom($title, $body, $icon)
->priority('high')
->expiresNow();
}
}
Use the NotificationBell facade to mark all as read:
NotificationBell::markAllAsRead();
Queue Stuck Notifications:
php artisan queue:work).'queue' => false,
Livewire Component Not Rendering:
@livewire directive is in your layout after the <head> but before </body>.php artisan livewire:discover
Dark Mode Conflicts:
<html class="dark">
.dark .bell-notification {
background-color: #334155;
}
Notification Persistence:
auth()->user()->notifications()->where('created_at', '<', now()->subDays(30))->forceDelete();
Log Queued Jobs:
Add this to your AppServiceProvider:
NotificationBell::setLogger(function ($message) {
\Log::debug('NotificationBell: ' . $message);
});
Inspect Database:
Check the notifications table for stuck jobs:
SELECT * FROM notifications WHERE read_at IS NULL LIMIT 10;
Disable Auto-Dismiss:
Temporarily set 'autoDismiss' => false in config to debug visibility.
Custom Storage: Override the notification model by binding your own:
NotificationBell::setNotificationModel(App\Models\CustomNotification::class);
Event Listeners:
Listen for notification events (e.g., NotificationCreated):
use CaiqueBispo\NotificationBell\Events\NotificationCreated;
NotificationCreated::listen(function ($notification) {
\Log::info('New notification created: ' . $notification->title);
});
API Endpoints: Expose notifications via API using Laravel Sanctum/Passport:
Route::middleware('auth:sanctum')->get('/notifications', [NotificationController::class, 'index']);
NotificationBell::batch() to group related notifications:
NotificationBell::batch('System Updates')
->add(NotificationBell::success('Update 1', 'Details...'))
->add(NotificationBell::warning('Update 2', 'Details...'));
config/notification-bell.php:
'labels' => [
'new_notifications' => 'You have __count__ new notifications',
],
public function mount()
{
$this->notifications = auth()->user()->notifications()->latest()->take(50)->get();
}
How can I help you explore Laravel packages today?