Installation:
composer require chapuzzo/notificationsbundle
Add to config/app.php under providers:
Chapuzzo\NotificationsBundle\NotificationsBundle::class,
Publish the config:
php artisan vendor:publish --provider="Chapuzzo\NotificationsBundle\NotificationsBundle" --tag=config
First Use Case:
Email or Slack) in config/notifications.php.Chapuzzo\NotificationsBundle\Notification:
namespace App\Notifications;
use Chapuzzo\NotificationsBundle\Notification;
class WelcomeEmail extends Notification
{
public function getChannel()
{
return 'email';
}
public function getData()
{
return ['subject' => 'Welcome!', 'content' => 'Thanks for signing up.'];
}
}
use App\Notifications\WelcomeEmail;
use Chapuzzo\NotificationsBundle\NotificationManager;
public function sendWelcome(NotificationManager $manager)
{
$manager->send(new WelcomeEmail(), $user);
}
Channel Integration:
Chapuzzo\NotificationsBundle\Channel\ChannelInterface for custom channels (e.g., SMS, Push).config/notifications.php:
'channels' => [
'email' => [
'class' => 'Chapuzzo\NotificationsBundle\Channel\EmailChannel',
'options' => ['host' => 'smtp.example.com'],
],
'slack' => [
'class' => 'App\Channels\SlackChannel',
],
],
Dynamic Notifications:
public function getData()
{
return ['user' => $this->user, 'token' => $this->generateToken()];
}
Queue Support:
config/notifications.php:
'queue' => [
'enabled' => true,
'connection' => 'database',
],
$manager->sendLater(new WelcomeEmail(), $user, now()->addMinutes(5));
Event Listeners:
$manager->send(new WelcomeEmail(), $user)
->onSent(function ($notification) {
Log::info("Notification sent: {$notification->getName()}");
});
Outdated Dependencies:
laravel/framework:^5.4) or fork the package.Channel Configuration:
config/notifications.php.Queue Delays:
sendLater method uses Laravel’s queue delays, but the package lacks built-in retry logic.Illuminate\Queue\InteractsWithQueue in custom notifications for retries.Missing Events:
failed notifications. Override Chapuzzo\NotificationsBundle\Events\NotificationSent for custom logic.Log Channel Output:
public function send($notifiable, array $data)
{
Log::debug('Channel data:', $data);
// Original logic...
}
Check Queue Jobs:
.env:
QUEUE_CONNECTION=database
QUEUE_FAILED_TABLE=failed_jobs
Configuration Overrides:
'channels.email.options.host' => env('NOTIFICATION_SMTP_HOST'),
Custom Notifiable:
Chapuzzo\NotificationsBundle\Notifiable:
use Chapuzzo\NotificationsBundle\Notifiable;
class User implements Notifiable
{
public function routeNotificationFor($channel)
{
return $channel === 'email' ? $this->email : null;
}
}
Middleware:
$manager->send(new WelcomeEmail(), $user)
->through(function ($notifiable, $notification) {
return [$this->throttleUsersByKey($notifiable)];
});
Testing:
NotificationManager in tests:
$manager = Mockery::mock(NotificationManager::class);
$manager->shouldReceive('send')->once();
How can I help you explore Laravel packages today?