[
](https://packagist.org/packages/zanko-khaledi/notifications) [
](https://packagist.org/packages/zanko-khaledi/notifications) [
](https://github.com/zanko-khaledi/notifications/blob/master/LICENSE) [
](https://php.net) [
A flexible, event-driven Laravel package for managing and dispatching notifications.
It provides both synchronous and asynchronous (queued) notification handling, with support for notification pools, custom drivers, and a base Notification class for building reusable notification types.
Synchronous & Asynchronous sending
Send notifications immediately or queue them for background processing.
Job-based async execution
Uses Laravelβs NotificationJob to handle queued notifications.
Notification pools
Group multiple notification drivers together and process them in sequence.
Contracts for extensibility
Define your own notification drivers by implementing the provided interfaces.
Abstract Notification base class
Provides a reusable foundation for building custom notification types with user, notifiable models, and collections.
Require the package in your Laravel app:
composer require zanko-khaledi/notifications:@dev
php artisan vendor:publish --tag=notifications-config
php artisan vendor:publish --tag=notifications-model
php artisan migrate
use ZankoKhaledi\Notifications\NotificationService;
use App\Notifications\MyNotification; // implements NotificationInterface
$service = app(NotificationService::class);
$user = auth()->user();
$notifiables = User::query()->where("id", ">", 2)->get();
$notification = app(MyNotification::class);
$notification->setUser($user)->setTitle("New notification")
->setMessage("Hello World")->setNotifiable($notifiables)
// Send synchronously
$service->send($notification);
// Send asynchronously (queued)
$service->send($notification,async:true);
// Determine queue and connection
$service->onQueue("notifications")->onConnection("redis")
->send($notification,async:true);
use App\Models\User;
use ZankoKhaledi\Notifications\Contracts\NotificationInterface;
use ZankoKhaledi\Notifications\NotificationService;
use App\Notifications\Telegram;
use App\Notifications\System;
$user = auth()->user();
$notifiables = User::query()->where("id", ">", 2)->get();
$notificationService = app(NotificationService::class);
// notifications sent via queue & background processing with pool
$notificationService->pool([
Telegram::class,
System::class
])->then(fn(NotificationInterface $notification) =>
$notification->setUser($user)
->setTitle("Hi")
->setMessage("Hello World")
->setNotifiable($notifiables)
);
This example demonstrates how to send notifications to multiple drivers (Telegram, System) using a pool.
use ZankoKhaledi\Notifications\Notification;
use ZankoKhaledi\Notifications\Contracts\NotificationInterface;
class SystemNotification extends Notification implements NotificationInterface
{
#[\Override]
public function send() : \ZankoKhaledi\Notifications\Models\Notification
{
$model = parent::send();
// you can send you're notification via broadcast channel to websocket server then any consumers could catch the notification
broadcast(new NotificationEvent($model));
return $model;
}
}
namespace App\Services\Notifications;
use Exception;
use Illuminate\Support\Facades\Http;
use ZankoKhaledi\Notifications\Contracts\NotificationInterface;
use ZankoKhaledi\Notifications\Models\Notification as ModelsNotification;
use ZankoKhaledi\Notifications\Notification;
class Telegram extends Notification implements NotificationInterface
{
#[\Override]
public function send(): ModelsNotification
{
$model = parent::send();
$url = config('notifications.telegram_url', 'https://api.telegram.org/bot'.env('TELEGRAM_BOT_TOKEN').'/sendMessage');
$response = Http::post($url, [
'chat_id' => $this->getUser()?->id,
'text' => $this->getMessage(),
]);
if ($response->successful()) {
return $model;
}
throw new Exception(sprintf('Telegram API error: %s', $response->body()));
}
}
Laravel's notification system is great for single-channel, fire-and-forget messages. This package adds what's missing for larger systems:
Notification classes per channel.send($notification, true) queues automatically via a dedicated job, no manual ShouldQueue boilerplate.Use Laravel's native notifications for simple cases. Use this package when you need pooled, multi-driver, queue-first dispatching.
src/
βββ NotificationService.php
βββ Notification.php (abstract base class)
βββ Jobs/
β βββ NotificationJob.php
βββ Contracts/
βββ NotificationInterface.php
βββ NotificationAsyncInterface.php
βββ NotificationPoolInterface.php
βββ NotificationServiceInterface.php
This package is open-sourced software licensed under the MIT license
How can I help you explore Laravel packages today?