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

Notifier Message Laravel Package

coka/notifier-message

Base library providing a common message class for notifier implementations. Install via Composer and extend it to standardize notification message data across your PHP/Laravel channels. Includes changelog/upgrade notes and MIT license.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation

    composer require coka/notifier-message
    

    Register the service provider in config/app.php:

    'providers' => [
        // ...
        CedrickOka\NotifierMessage\NotifierMessageServiceProvider::class,
    ],
    
  2. Publish Config (Optional)

    php artisan vendor:publish --provider="CedrickOka\NotifierMessage\NotifierMessageServiceProvider"
    

    Config file: config/notifier-message.php.

  3. First Use Case Send a basic message via a channel (e.g., mail or slack):

    use CedrickOka\NotifierMessage\Facades\NotifierMessage;
    
    NotifierMessage::send('user@example.com', 'welcome', [
        'name' => 'John Doe',
    ]);
    

Implementation Patterns

Core Workflows

  1. Channel-Based Messaging Define channels in config/notifier-message.php:

    'channels' => [
        'mail' => [
            'driver' => 'mail',
            'options' => [
                'from' => 'noreply@example.com',
            ],
        ],
        'slack' => [
            'driver' => 'slack',
            'options' => [
                'webhook_url' => env('SLACK_WEBHOOK_URL'),
            ],
        ],
    ],
    

    Send via a channel:

    NotifierMessage::channel('slack')->send('team-channel', 'alert', ['message' => 'System down!']);
    
  2. Custom Templates Store templates in resources/views/notifier-message/. Example:

    resources/
    └── views/
        └── notifier-message/
            ├── mail/welcome.blade.php
            └── slack/alert.blade.php
    

    Reference in config:

    'templates' => [
        'welcome' => 'mail::welcome',
        'alert' => 'slack::alert',
    ],
    
  3. Event-Driven Triggers Listen for events (e.g., user.registered) and dispatch messages:

    use CedrickOka\NotifierMessage\Events\MessageSent;
    
    event(new MessageSent('user@example.com', 'welcome'));
    

Integration Tips

  • Laravel Notifications: Extend the package to support Illuminate\Notifications\Notification:
    NotifierMessage::extend('notification', function ($notifiable, $notification) {
        return NotifierMessage::send($notifiable->getEmail(), $notification->via(), $notification->toArray());
    });
    
  • Queue Jobs: Delay messages with Laravel Queues:
    NotifierMessage::later(now()->addMinutes(5))->send('user@example.com', 'reminder');
    

Gotchas and Tips

Pitfalls

  1. Channel Driver Mismatch Ensure the driver in config/notifier-message.php matches a registered channel (e.g., mail, slack). Defaults to mail if unspecified.

  2. Template Paths Blade templates must follow the resources/views/notifier-message/{channel}/{template}.blade.php structure. Misspelled paths throw TemplateNotFoundException.

  3. Async Failures If using queues, unhandled exceptions in channel drivers (e.g., Slack webhook failures) won’t trigger Laravel’s failed job handler. Wrap in try-catch:

    try {
        NotifierMessage::send('user@example.com', 'welcome');
    } catch (\Exception $e) {
        \Log::error("Message failed: " . $e->getMessage());
    }
    

Debugging

  • Log Output: Enable debug mode in config:

    'debug' => env('NOTIFIER_DEBUG', false),
    

    Logs will appear in storage/logs/laravel.log.

  • Channel-Specific Errors: Check config/notifier-message.php for options like timeout (Slack) or from (Mail). Invalid configs may silently fail.

Extension Points

  1. Custom Channels Create a new channel class:

    namespace App\Channels;
    
    use CedrickOka\NotifierMessage\Contracts\Channel;
    
    class CustomChannel implements Channel {
        public function send($recipient, $template, array $data) {
            // Custom logic (e.g., SMS, Telegram)
        }
    }
    

    Register in config:

    'channels' => [
        'custom' => [
            'driver' => 'custom',
            'class' => App\Channels\CustomChannel::class,
        ],
    ],
    
  2. Middleware Add middleware to modify messages before sending:

    NotifierMessage::middleware(function ($message) {
        $message->data['footer'] = '© 2023';
    });
    
  3. Testing Mock the facade in tests:

    $this->partialMock(NotifierMessage::class, 'send')
         ->shouldReceive('send')
         ->once()
         ->with('user@example.com', 'welcome', ['name' => 'John']);
    
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.
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
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours