PHPackages                             kiwilan/notifier-laravel - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Logging &amp; Monitoring](/categories/logging)
4. /
5. kiwilan/notifier-laravel

ActiveLibrary[Logging &amp; Monitoring](/categories/logging)

kiwilan/notifier-laravel
========================

Notifier for Laravel is a package to send notifications and monitoring, built for Discord, Slack and mails.

0.3.18(1y ago)21.6k[5 PRs](https://github.com/kiwilan/notifier-laravel/pulls)MITPHPPHP ^8.1CI passing

Since Feb 2Pushed 1mo agoCompare

[ Source](https://github.com/kiwilan/notifier-laravel)[ Packagist](https://packagist.org/packages/kiwilan/notifier-laravel)[ Docs](https://github.com/kiwilan/notifier-laravel)[ GitHub Sponsors](https://github.com/Kiwilan)[ RSS](/packages/kiwilan-notifier-laravel/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (16)Versions (25)Used By (0)

**Notifier for Laravel**
========================

[](#notifier-for-laravel)

[![Banner with british letter box picture in background and Notifier for Laravel title](https://raw.githubusercontent.com/kiwilan/notifier-laravel/main/docs/banner.jpg)](https://raw.githubusercontent.com/kiwilan/notifier-laravel/main/docs/banner.jpg)

[![php](https://camo.githubusercontent.com/731af46a12737ef77d62979aae24e91e42c2d5dcad6b2ef112eb0cd421851955/68747470733a2f2f696d672e736869656c64732e696f2f7374617469632f76313f7374796c653d666c61742d737175617265266c6162656c3d504850266d6573736167653d76382e3126636f6c6f723d373737424234266c6f676f3d706870266c6f676f436f6c6f723d666666666666266c6162656c436f6c6f723d313831383162)](https://www.php.net/)[![laravel](https://camo.githubusercontent.com/1f48dd8ce7ba417e3d67f3084d02c0ee029c7c48fcb5d2361ff47551a46a9ca1/68747470733a2f2f696d672e736869656c64732e696f2f7374617469632f76313f6c6162656c3d4c61726176656c266d6573736167653d7631302d3131267374796c653d666c61742d73717561726526636f6c6f72413d31383138314226636f6c6f72423d464632443230)](https://laravel.com)

[![version](https://camo.githubusercontent.com/f51325b0ae1c733ae04049e06b49066914a588f0444f7c6be5be90ebf96e67a4/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6b6977696c616e2f6e6f7469666965722d6c61726176656c2e7376673f7374796c653d666c61742d73717561726526636f6c6f72413d31383138314226636f6c6f72423d373737424234)](https://packagist.org/packages/kiwilan/notifier-laravel)[![downloads](https://camo.githubusercontent.com/e839704a29e9e593d8e67897b19e2482803c4a2b776402b3be1216c1aba68ee5/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6b6977696c616e2f6e6f7469666965722d6c61726176656c2e7376673f7374796c653d666c61742d73717561726526636f6c6f72413d31383138314226636f6c6f72423d373737424234)](https://packagist.org/packages/kiwilan/notifier-laravel)[![license](https://camo.githubusercontent.com/3bfc5bf23b751542ba62839d22a3f3f4dd57bfb7f50709522fca211e9eb14eaa/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6b6977696c616e2f6e6f7469666965722d6c61726176656c2e7376673f7374796c653d666c61742d73717561726526636f6c6f72413d31383138314226636f6c6f72423d373737424234)](https://github.com/kiwilan/notifier-laravel/blob/main/README.md)[![tests](https://camo.githubusercontent.com/acdd4efe26fbdeaaa0bc3fb22caa976112c8ac38e6294c9048548922f95724f4/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6b6977696c616e2f6e6f7469666965722d6c61726176656c2f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d73717561726526636f6c6f72413d313831383142)](https://github.com/kiwilan/notifier-laravel/actions/workflows/run-tests.yml)[![codecov](https://camo.githubusercontent.com/63a8d0d7478debd4d4a8dbf7d95c0152d7b2d5030c0692cc1083e75ae6abc889/68747470733a2f2f636f6465636f762e696f2f67682f6b6977696c616e2f6e6f7469666965722d6c61726176656c2f6272616e63682f6d61696e2f67726170682f62616467652e7376673f746f6b656e3d31707931666b36767763)](https://codecov.io/gh/kiwilan/notifier-laravel)

Notifier for Laravel is a package to send notifications (with `Notifier`) and monitoring (with `Journal`), built for Discord, Slack and mails.

Based on [`kiwilan/php-notifier`](https://github.com/kiwilan/php-notifier).

Important

This package does not support push notifications or SMS (if you interested, a PR is welcome) on [`kiwilan/php-notifier`](https://github.com/kiwilan/php-notifier).

About
-----

[](#about)

Laravel offers a built-in [Notification](https://laravel.com/docs/10.x/notifications) and [Laravel Logging](https://laravel.com/docs/10.x/logging) systems, this package is an alternative to these systems.

`Notifier` allows to send notifications without link to a user model and advanced and `Journal` is based on `Log` facade. `Journal` can write logs send notifications and write logs in the database with `filament/notifications` package (not included and not required).

When native Laravel notifications are for users, this package is designed for developers to help for debugging and monitoring, but you can use it for users too.

This package offer a support for Discord and Slack webhooks, but Slack has only basic support (without legacy API support), for more, you can use [`laravel/slack-notification-channel`](https://github.com/laravel/slack-notification-channel). To avoid dependencies, this package doesn't use it.

- [Discord webhooks](https://support.discord.com/hc/en-us/articles/228383668-Intro-to-Webhooks): support message and rich embeds.
- [Slack webhooks](https://api.slack.com/messaging/webhooks): support message, attachments.
- Mail: support message and attachments with [`symfony/mailer`](https://symfony.com/doc/current/mailer.html).

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require kiwilan/notifier-laravel
```

You can publish the config file with:

```
php artisan vendor:publish --tag="notifier-config"
```

Note

The configuration file is totally optional, if you have multiple webhooks, you can create your own configs to send notifications.

This is the contents of the published config file:

```
return [
    // Default notifier client to send HTTP request, can be `stream`, `curl` or `guzzle`.
    // `guzzle` is not included in this package, you need to install it manually.
    'client' => env('NOTIFIER_CLIENT', 'stream'),

    'discord' => [
        // Default Discord webhook URL.
        'webhook' => env('NOTIFIER_DISCORD_WEBHOOK', null),
        // Default Discord username.
        'username' => env('NOTIFIER_DISCORD_USERNAME', null),
        // Default Discord avatar URL.
        'avatar_url' => env('NOTIFIER_DISCORD_AVATAR_URL', null),
    ],

    'mail' => [
        // Use Laravel mailer instead package from `.env` file.
        'laravel_override' => env('NOTIFIER_MAIL_LARAVEL_OVERRIDE', false),
        // Set default subject for mail.
        'subject' => env('NOTIFIER_MAIL_SUBJECT', 'Notifier'),
        // Set default mailer from `.env` file.
        'mailer' => env('NOTIFIER_MAIL_MAILER', 'smtp'),
        'host' => env('NOTIFIER_MAIL_HOST', 'mailpit'),
        'port' => env('NOTIFIER_MAIL_PORT', 1025),
        'username' => env('NOTIFIER_MAIL_USERNAME', null),
        'password' => env('NOTIFIER_MAIL_PASSWORD', null),
        'encryption' => env('NOTIFIER_MAIL_ENCRYPTION', 'tls'),
        'from_address' => env('NOTIFIER_MAIL_FROM_ADDRESS', null),
        'from_name' => env('NOTIFIER_MAIL_FROM_NAME', null),
        'to_address' => env('NOTIFIER_MAIL_TO_ADDRESS', null),
        'to_name' => env('NOTIFIER_MAIL_TO_NAME', null),
    ],

    'slack' => [
        // Default Slack webhook URL.
        'webhook' => env('NOTIFIER_SLACK_WEBHOOK', null),
    ],

    'http' => [
        // Default HTTP URL to send request.
        'url' => env('NOTIFIER_HTTP_URL', null),
    ],

    // This feature use `filament/notifications` package, not included in this package.
    'to_database' => [
        // Default user model for notification.
        'model' => env('NOTIFIER_TO_DATABASE_USER', 'App\Models\User'),
        // Recipients ID for notification.
        'recipients_id' => explode(',', env('NOTIFIER_TO_DATABASE_RECIPIENTS_ID', '')),
    ],

    'journal' => [
        // Write logs for debugging when notifications are sent.
        'debug' => env('NOTIFIER_JOURNAL_DEBUG', false),
        // Write error logs with `error_log` function, in addition to Laravel log.
        'use_error_log' => env('NOTIFIER_JOURNAL_USE_ERROR_LOG', true),
    ],
];
```

Usage
-----

[](#usage)

### Journal

[](#journal)

Journal is a utility class for [Laravel Logging](https://laravel.com/docs/10.x/logging).

```
use Kiwilan\Notifier\Facades\Journal;

Journal::debug('Hello, Journal!');
Journal::info('Hello, Journal!');
Journal::warning('Hello, Journal!');
Journal::error('Hello, Journal!');
```

#### To database

[](#to-database)

You can use Journal to log in the database with `filament/notifications` package (you have to install it).

This method will search `App\Models\User::class` and get all users with `canAccessPanel()` allowed, by default all users with access will be notified.

```
use Kiwilan\Notifier\Facades\Journal;

Journal::info('Hello, Journal!')
  ->toDatabase();
```

#### To notifier

[](#to-notifier)

You can use Journal to send a notification with `discord`, `mail` or `slack` (you have to set the config file).

```
use Kiwilan\Notifier\Facades\Journal;

Journal::info('Hello, Journal!')
  ->toNotifier('discord');
```

#### Handler

[](#handler)

You can use Journal as a handler for [Laravel Exceptions](https://laravel.com/docs/10.x/errors).

- `toDatabase` is a boolean to log the exception in the database with `filament/notifications` package (you have to install it).
- `toNotifier` is a string to send a notification with `discord`, `mail` or `slack` (you have to set the config file).

```
