Installation
composer require creavo/notify-task-bundle
For Laravel (not Symfony), use:
composer require creavo/notify-task-bundle
Then register the service provider in config/app.php under providers:
Creavo\NotifyTaskBundle\CreavoNotifyTaskBundle::class,
Publish Config
php artisan vendor:publish --provider="Creavo\NotifyTaskBundle\CreavoNotifyTaskBundle" --tag="config"
This creates config/notify_task.php. Update with your preferences (e.g., send_notification_immediately).
Run Migrations
php artisan migrate
(If using Doctrine, follow Symfony docs; Laravel users should adapt the schema to migrations.)
First Use Case Trigger a notification via a command or event:
use Creavo\NotifyTaskBundle\Service\NotificationService;
$notification = $this->container->get(NotificationService::class);
$notification->create([
'title' => 'Task Completed',
'message' => 'Your task is done!',
'type' => 'success', // or 'error', 'warning'
'user_id' => 1,
]);
Event-Driven Notifications
Bind to Laravel events (e.g., job.processed) and dispatch notifications:
use Creavo\NotifyTaskBundle\Events\NotificationCreated;
event(new NotificationCreated($data));
Queue-Based Delayed Notifications
Disable send_notification_immediately in config and use queues:
$notification->create($data, ['delay' => 3600]); // Delay 1 hour
Multi-Channel Notifications
Enable pushover_enabled and email_enabled in config. The bundle auto-routes to configured channels.
Custom Notification Types
Extend the Notification entity or create a custom service:
$notification->create([
'type' => 'custom',
'custom_data' => ['key' => 'value'],
]);
use Creavo\NotifyTaskBundle\Traits\Notifiable;
class TaskController {
use Notifiable;
// ...
}
return $this->notifyAndReturn($request, 'Task updated', $response);
NotificationService in tests:
$this->partialMock(NotificationService::class, ['create']);
Symfony vs. Laravel Confusion
Kernel and config.yml. For Laravel:
AppKernel.php instructions.config/notify_task.php (published via vendor:publish).doctrine:schema:update with Laravel migrations.Queue Configuration
send_notification_immediately = false and the notify_task:send queue is processed:
php artisan queue:work
Pushover/Email Dependencies
pushover_enabled/email_enabled only after configuring their respective tokens/mailers. Unconfigured channels will throw errors.Database Schema
notifications table. Customize via migrations if extending:
Schema::table('notifications', function (Blueprint $table) {
$table->string('custom_field')->nullable();
});
storage/logs/laravel.log for notification failures.notify_task:send jobs with:
php artisan queue:failed-table
php artisan queue:retry <job-id>
NOTIFY_TASK_PUSHOVER_ENABLED=true
NOTIFY_TASK_EMAIL_FROM=no-reply@example.com
Custom Channels
Implement Creavo\NotifyTaskBundle\Channel\ChannelInterface:
class SlackChannel implements ChannelInterface {
public function send(Notification $notification) { ... }
}
Register in config/notify_task.php:
'channels' => [
'slack' => Creavo\NotifyTaskBundle\Channel\SlackChannel::class,
],
Notification Filters Use middleware to filter notifications:
$notification->create($data, [
'middleware' => [YourMiddleware::class],
]);
Webhooks
Extend the bundle to support webhook notifications by adding a webhook channel and configuring endpoints in the Notification entity.
How can I help you explore Laravel packages today?