Sending notifications | laravel-comments | Spatie

 SPATIE

laravel-comments
================

spatie.be/open-source

  [Docs](https://spatie.be/docs)  [Laravel-comments](https://spatie.be/docs/laravel-comments/v1)  Basic-usage  Sending notifications

 Version   v2   v1

 Other versions for crawler [v2](https://spatie.be/docs/laravel-comments/v2) [v1](https://spatie.be/docs/laravel-comments/v1)

- [ Introduction ](https://spatie.be/docs/laravel-comments/v1/introduction)
- [ Getting a license ](https://spatie.be/docs/laravel-comments/v1/getting-a-license)
- [ Requirements ](https://spatie.be/docs/laravel-comments/v1/requirements)
- [ Installation &amp; setup ](https://spatie.be/docs/laravel-comments/v1/installation-setup)
- [ Questions and issues ](https://spatie.be/docs/laravel-comments/v1/questions-issues)
- [ Changelog ](https://spatie.be/docs/laravel-comments/v1/changelog)
- [ About us ](https://spatie.be/docs/laravel-comments/v1/about-us)

Basic usage
-----------

- [ Working with comments ](https://spatie.be/docs/laravel-comments/v1/basic-usage/working-with-comments)
- [ Working with reactions ](https://spatie.be/docs/laravel-comments/v1/basic-usage/working-with-reactions)
- [ Transforming comments ](https://spatie.be/docs/laravel-comments/v1/basic-usage/transforming-comments)
- [ Sending notifications ](https://spatie.be/docs/laravel-comments/v1/basic-usage/sending-notifications)
- [ Approving comments ](https://spatie.be/docs/laravel-comments/v1/basic-usage/approving-comments)
- [ Listing comments in Laravel Nova ](https://spatie.be/docs/laravel-comments/v1/basic-usage/listing-comments-in-laravel-nova)

Livewire components
-------------------

- [ Introduction ](https://spatie.be/docs/laravel-comments/v1/livewire-components/introduction)
- [ Installation ](https://spatie.be/docs/laravel-comments/v1/livewire-components/installation)
- [ Using the components ](https://spatie.be/docs/laravel-comments/v1/livewire-components/using-the-components)
- [ Taking care of authorization ](https://spatie.be/docs/laravel-comments/v1/livewire-components/taking-care-of-authorization)
- [ Customising the views ](https://spatie.be/docs/laravel-comments/v1/livewire-components/customising-the-views)
- [ Miscellaneous options ](https://spatie.be/docs/laravel-comments/v1/livewire-components/miscellaneous-options)
- [ Using Markdown ](https://spatie.be/docs/laravel-comments/v1/livewire-components/using-markdown)
- [ Upgrading laravel-comments-livewire ](https://spatie.be/docs/laravel-comments/v1/livewire-components/upgrading)

      You are viewing the documentation for **an older version** of this package. You can check the version you are using with the following command:

 `                                    composer show spatie/laravel-comments                                                                                                                                                                                                                                    `

Sending notifications
=====================

###  On this page

1. [ Subscribing to notifications ](#content-subscribing-to-notifications)
2. [ Unsubscribing from notifications ](#content-unsubscribing-from-notifications)
3. [ Customizing notifications ](#content-customizing-notifications)

Whenever somebody creates a comments, this package can send a notification when comments are made. Out of the box such a notification is always an email.

Subscribing to notifications
--------------------------------------------------------------------------------------------------------------------------------------------

You can let a user subscribe to notifications like this:

```
use \Spatie\Comments\Enums\NotificationSubscriptionType;

$user->subscribeToCommentNotifications($model, NotificationSubscriptionType::All);
```

This will send a notification to `$user` whenever a comment is posted by anyone to the given `$model`.

You can also only send a notification to `$user` when a new comment is posted on things that `$user` already commented on. For the behaviour, use ` NotificationSubscriptionType::Participating`

```
use \Spatie\Comments\Enums\NotificationSubscriptionType;

$user->subscribeToCommentNotifications($model, NotificationSubscriptionType::Participating);
```

Unsubscribing from notifications
--------------------------------------------------------------------------------------------------------------------------------------------------------

Here's how you can unsubscribe a user from getting notified when a new comment is posted

```
$user->unsubscribeFromCommentNotifications($model);
```

To let a user unsubscribe from all notifications for all models, you can use this method:

```
$user->unsubscribeFromAllCommentNotifications();
```

Customizing notifications
-----------------------------------------------------------------------------------------------------------------------------------

Out of the box, this package will send notifications as emails.

You can customize the content of the mail by publishing the views:

```
php artisan vendor:publish --tag="comments-views"
```

You'll find the Blade views to customize in `resources/vendor/comments/`.

To customize the notifications itself (to for instance add new channels) you create your own notification class that extends either `Spatie\Comments\Notifications\PendingCommentNotification` or `Spatie\Comments\Notifications\ApprovedCommentNotification`. You should specify your class name in the `pending_comment` or `approved_comment` key of the `comments` config file.
