Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Notificationsbundle Laravel Package

chapuzzo/notificationsbundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. 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
    
  2. First Use Case:

    • Define a notification channel (e.g., Email or Slack) in config/notifications.php.
    • Create a notification class extending 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.'];
          }
      }
      
    • Dispatch the notification in a controller:
      use App\Notifications\WelcomeEmail;
      use Chapuzzo\NotificationsBundle\NotificationManager;
      
      public function sendWelcome(NotificationManager $manager)
      {
          $manager->send(new WelcomeEmail(), $user);
      }
      

Implementation Patterns

Core Workflows

  1. Channel Integration:

    • Extend Chapuzzo\NotificationsBundle\Channel\ChannelInterface for custom channels (e.g., SMS, Push).
    • Register channels in config/notifications.php:
      'channels' => [
          'email' => [
              'class' => 'Chapuzzo\NotificationsBundle\Channel\EmailChannel',
              'options' => ['host' => 'smtp.example.com'],
          ],
          'slack' => [
              'class' => 'App\Channels\SlackChannel',
          ],
      ],
      
  2. Dynamic Notifications:

    • Use dependency injection for dynamic data:
      public function getData()
      {
          return ['user' => $this->user, 'token' => $this->generateToken()];
      }
      
  3. Queue Support:

    • Configure config/notifications.php:
      'queue' => [
          'enabled' => true,
          'connection' => 'database',
      ],
      
    • Dispatch notifications via queues:
      $manager->sendLater(new WelcomeEmail(), $user, now()->addMinutes(5));
      
  4. Event Listeners:

    • Attach listeners to notifications:
      $manager->send(new WelcomeEmail(), $user)
              ->onSent(function ($notification) {
                  Log::info("Notification sent: {$notification->getName()}");
              });
      

Gotchas and Tips

Pitfalls

  1. Outdated Dependencies:

    • The package relies on older Laravel versions (pre-5.5). Test thoroughly with Laravel 5.4 or lower.
    • Fix: Use a compatibility layer (e.g., laravel/framework:^5.4) or fork the package.
  2. Channel Configuration:

    • Hardcoded channel paths may break if the bundle structure changes.
    • Tip: Use fully qualified class names in config/notifications.php.
  3. Queue Delays:

    • The sendLater method uses Laravel’s queue delays, but the package lacks built-in retry logic.
    • Tip: Implement Illuminate\Queue\InteractsWithQueue in custom notifications for retries.
  4. Missing Events:

    • No built-in events for failed notifications. Override Chapuzzo\NotificationsBundle\Events\NotificationSent for custom logic.

Debugging Tips

  1. Log Channel Output:

    • Temporarily extend channels to log payloads:
      public function send($notifiable, array $data)
      {
          Log::debug('Channel data:', $data);
          // Original logic...
      }
      
  2. Check Queue Jobs:

    • Inspect failed jobs in .env:
      QUEUE_CONNECTION=database
      QUEUE_FAILED_TABLE=failed_jobs
      
  3. Configuration Overrides:

    • Use environment variables to override config:
      'channels.email.options.host' => env('NOTIFICATION_SMTP_HOST'),
      

Extension Points

  1. Custom Notifiable:

    • Implement Chapuzzo\NotificationsBundle\Notifiable:
      use Chapuzzo\NotificationsBundle\Notifiable;
      
      class User implements Notifiable
      {
          public function routeNotificationFor($channel)
          {
              return $channel === 'email' ? $this->email : null;
          }
      }
      
  2. Middleware:

    • Add middleware to notifications:
      $manager->send(new WelcomeEmail(), $user)
              ->through(function ($notifiable, $notification) {
                  return [$this->throttleUsersByKey($notifiable)];
              });
      
  3. Testing:

    • Mock the NotificationManager in tests:
      $manager = Mockery::mock(NotificationManager::class);
      $manager->shouldReceive('send')->once();
      
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
codeflextech/permission-manager
karnoweb/livewire-datepicker
sayedenam/sayed-dashboard
milito/query-filter
apiboxsym/user-bundle
apiboxsym/health-check-bundle
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui
babelqueue/php-sdk
facebook/capi-param-builder-php
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver