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

Rms Push Notifications Bundle Laravel Package

ciricihq/rms-push-notifications-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation Add the package via Composer:

    composer require richsage/rms-push-notifications-bundle:dev-master
    

    Enable the bundle in app/AppKernel.php:

    new RMS\PushNotificationsBundle\RMSPushNotificationsBundle(),
    
  2. Configuration Define your platform-specific credentials in app/config/config.yml:

    rms_push_notifications:
        android:
            gcm:
                api_key: "YOUR_GCM_SERVER_KEY"
        ios:
            certificate_path: "%kernel.root_dir%/path/to/certificate.pem"
            passphrase: "CERTIFICATE_PASSPHRASE"
    
  3. First Use Case Inject the PushNotificationService into a controller/service and send a notification:

    use RMS\PushNotificationsBundle\Service\PushNotificationService;
    
    class NotificationController extends Controller
    {
        public function sendNotification(PushNotificationService $pushService)
        {
            $notification = [
                'message' => 'Hello from Laravel!',
                'badge' => 1,
                'sound' => 'default',
            ];
    
            $pushService->sendToDevice('ios', 'DEVICE_TOKEN', $notification);
        }
    }
    

Implementation Patterns

Core Workflows

  1. Device Registration Store device tokens (e.g., GCM/iOS tokens) in your database for later use:

    // Example: Store token in DB after registration
    $user->devices()->create([
        'platform' => 'ios',
        'token' => $request->get('device_token'),
    ]);
    
  2. Batched Sending Use the sendToMultipleDevices() method for bulk notifications:

    $tokens = ['ios_token_1', 'ios_token_2'];
    $pushService->sendToMultipleDevices('ios', $tokens, $notification);
    
  3. Platform-Specific Customization Override default payloads per platform in config:

    rms_push_notifications:
        ios:
            default_payload:
                category: "alert"
                content_available: true
    
  4. Event Listeners Extend functionality via Symfony events (e.g., log failed sends):

    // src/RMS/PushNotificationsBundle/EventListener/NotificationListener.php
    public function onNotificationSent(NotificationSentEvent $event)
    {
        if (!$event->isSuccess()) {
            $this->logger->error('Failed to send notification', [
                'device' => $event->getDeviceToken(),
                'error' => $event->getError(),
            ]);
        }
    }
    

Gotchas and Tips

Common Pitfalls

  1. Certificate Handling (iOS)

    • Ensure the .pem certificate is unencrypted or provide the correct passphrase.
    • Use absolute paths in certificate_path to avoid issues with Symfony’s %kernel.root_dir% resolution.
  2. GCM Multi-CURL

    • Disable use_multi_curl if sending to <100 devices to avoid memory issues:
      gcm:
          use_multi_curl: false
      
  3. Token Validation

    • Always validate device tokens before sending (e.g., check DB for existence):
      if (!$this->deviceRepository->exists($token)) {
          throw new \RuntimeException('Invalid device token');
      }
      
  4. Rate Limiting

    • GCM/iOS APIs throttle requests. Implement retries with exponential backoff:
      try {
          $pushService->sendToDevice('gcm', $token, $notification);
      } catch (RateLimitExceededException $e) {
          sleep(2 ** $attempt); // Exponential backoff
          retry();
      }
      

Debugging Tips

  • Enable Verbose Logging Add to config.yml:

    rms_push_notifications:
        debug: true
    

    Logs will include raw API responses for troubleshooting.

  • Dry Runs (GCM) Test without sending actual notifications:

    gcm:
        dry_run: true
    

Extension Points

  1. Custom Payload Builders Override the PayloadBuilder service to modify payloads dynamically:

    // services.yml
    rms_push_notifications.payload_builder:
        class: AppBundle\Service\CustomPayloadBuilder
        arguments: ["@rms_push_notifications.payload_builder.default"]
    
  2. Platform-Specific Services Extend the bundle by adding new platform services (e.g., for Web Push):

    // src/AppBundle/Service/WebPushService.php
    class WebPushService extends AbstractPushService
    {
        protected $platform = 'web';
        // ...
    }
    
  3. Event Dispatching Listen for rms_push_notifications.send and rms_push_notifications.sent events to intercept or modify notifications.

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.
emuniq/filament-browser-notifications
syriable/filament-translator
hungnm28/livewire-form
wenprise/eloquent
crudly/encrypted
fadion/bouncy
cuci/prototurk-sdk
gos/pubsub-router-bundle
cuci/prototurk-sdk-symfony
clementtalleu/easyadmin-markdown-bundle
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