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

Notification Bundle Laravel Package

dywee/notification-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation

    composer require dywee/notification-bundle
    

    Add to AppKernel.php (Symfony3):

    new Dywee\NotificationBundle\DyweeNotificationBundle(),
    
  2. First Use Case Trigger a notification for a user:

    use Dywee\NotificationBundle\Manager\NotificationManager;
    
    $notificationManager = $this->get('dywee_notification.manager');
    $notificationManager->createNotification(
        $userId, // Target user ID
        'system', // Channel (e.g., 'system', 'email', 'push')
        'welcome', // Notification type
        ['name' => 'John'] // Data payload
    );
    
  3. Where to Look First

    • Configuration: config.yml (if provided) or Resources/config/services.yml for bundle settings.
    • Manager Service: NotificationManager for core functionality.
    • Templates: Check Resources/views/ for default notification templates (if any).

Implementation Patterns

Core Workflow

  1. Notification Creation Use NotificationManager to dispatch notifications:

    $manager->createNotification(
        $userId,
        'email', // Channel
        'order_confirmation',
        ['order_id' => 123]
    );
    
  2. Channel-Specific Logic Extend or override channel handlers (e.g., EmailChannel, PushChannel) in Resources/config/notification_channels.yml:

    dywee_notification:
        channels:
            email:
                class: AppBundle\Notification\Channel\CustomEmailChannel
    
  3. Event Listeners Attach listeners to notification.created or notification.sent events:

    // In a service or controller
    $this->get('event_dispatcher')->dispatch(
        'notification.created',
        new NotificationEvent($notification)
    );
    
  4. Template Overrides Override default templates by copying them from the bundle to your theme:

    src/AppBundle/Resources/views/Notifications/
    

Integration Tips

  • Symfony Forms: Bind notification data to forms for user-triggered notifications.
  • Doctrine Events: Hook into postPersist/postUpdate to auto-generate notifications (e.g., for new comments).
  • Queue System: Use Symfony’s Messenger component to defer notification sending:
    $manager->sendNotificationAsync($userId, 'email', 'newsletter', $data);
    

Gotchas and Tips

Pitfalls

  1. Channel Configuration

    • Issue: Missing or misconfigured channels in notification_channels.yml will silently fail.
    • Fix: Validate channels exist and are properly autowired:
      dywee_notification:
          channels:
              email:
                  enabled: true
                  class: Dywee\NotificationBundle\Channel\EmailChannel
      
  2. User Context

    • Issue: Notifications may lack user context if $userId is invalid or the user object isn’t loaded.
    • Fix: Use Symfony’s UserProviderInterface to resolve users:
      $user = $this->get('security.token_storage')->getToken()->getUser();
      $manager->createNotification($user->getId(), ...);
      
  3. Template Inheritance

    • Issue: Overridden templates may not inherit layout if not extended properly.
    • Fix: Use Twig’s {% extends 'DyweeNotificationBundle::base.html.twig' %}.
  4. Debugging

    • Tip: Enable debug mode and check dywee_notification.logger for sent notifications:
      $this->get('dywee_notification.logger')->debug('Notification sent', ['data' => $data]);
      

Extension Points

  1. Custom Channels Implement Dywee\NotificationBundle\Channel\ChannelInterface:

    class SlackChannel implements ChannelInterface {
        public function send(Notification $notification) {
            // Slack API logic
        }
    }
    
  2. Notification Types Extend the Notification entity or use tags:

    $manager->createNotification($userId, 'email', 'promotion', $data, ['tag' => 'marketing']);
    
  3. Validation Add validation to NotificationManager via a subscriber:

    $event->setNotification($event->getNotification()->withData(['validated' => true]));
    
  4. Testing Mock NotificationManager in tests:

    $manager = $this->createMock(NotificationManager::class);
    $manager->expects($this->once())->method('createNotification');
    $this->container->set('dywee_notification.manager', $manager);
    
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.
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky
spatie/mailcoach-vapor
spatie/laravel-javascript-views