Introduction | laravel-notification-log | Spatie

 SPATIE

  Laravel Notification Log
===========================

spatie.be/open-source

  [Docs](https://spatie.be/docs)  [Laravel-notification-log](https://spatie.be/docs/laravel-notification-log/v1)  Introduction

 Version   v1

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

- [ Introduction ](https://spatie.be/docs/laravel-notification-log/v1/introduction)
- [ Support us ](https://spatie.be/docs/laravel-notification-log/v1/support-us)
- [ Requirements ](https://spatie.be/docs/laravel-notification-log/v1/requirements)
- [ Installation &amp; setup ](https://spatie.be/docs/laravel-notification-log/v1/installation-setup)
- [ Questions and issues ](https://spatie.be/docs/laravel-notification-log/v1/questions-issues)
- [ Changelog ](https://spatie.be/docs/laravel-notification-log/v1/changelog)
- [ About us ](https://spatie.be/docs/laravel-notification-log/v1/about-us)

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

- [ Getting started ](https://spatie.be/docs/laravel-notification-log/v1/basic-usage/getting-started)
- [ Determining which notifications get logged ](https://spatie.be/docs/laravel-notification-log/v1/basic-usage/determining-which-notifications-get-logged)
- [ Adding extra info to a logged notifications ](https://spatie.be/docs/laravel-notification-log/v1/basic-usage/adding-extra-info-to-your-notification)
- [ Querying the notification log ](https://spatie.be/docs/laravel-notification-log/v1/basic-usage/querying-the-notification-log)
- [ Working with fingerprints ](https://spatie.be/docs/laravel-notification-log/v1/basic-usage/working-with-fingerprints)

Advanced usage
--------------

- [ Customizing notification types ](https://spatie.be/docs/laravel-notification-log/v1/advanced-usage/customizing-notification-types)
- [ Customizing the logging process ](https://spatie.be/docs/laravel-notification-log/v1/advanced-usage/customizing-the-logging-process)
- [ Handling on demand notifications ](https://spatie.be/docs/laravel-notification-log/v1/advanced-usage/handling-on-demand-notifications)
- [ Using your own notification log model ](https://spatie.be/docs/laravel-notification-log/v1/advanced-usage/using-your-own-notification-log-model)

 Laravel Notification Log
==========================

 Log notifications sent by your Laravel app

 [    Repository ](https://github.com/spatie/laravel-notification-log)

    912,685

    207

Introduction
------------

This package will log all the notifications sent by your app. This will allow you to write logic based on the notifications your app has sent.

If you want to create a list of all notifications sent to a user

```
// returns a collection of `NotificationLogItem` models
$sentNotifications = $user->loggedNotifications();
```

In a view you could write this:

```

@foreach($sentNotifications as $sentNotification)
    {{ $sentNotification->notification_type }} at {{ $sentNotification->created_at->format('Y-m-d H:i:s') }}
@endforeach

```

The package also contains handy methods that allow you to make decisions based on the notifications sent. Here's an example, where we use the `wasSentTo` method provided by the package in the `shouldSend` method of a notification.

```
use Spatie\NotificationLog\Models\Concerns\HasHistory;

// in a notification

// set history trait
use HasHistory;

// verifying if the queued notification can be sent based in the history
public function shouldSend($notifiable)
{
      return ! $this
        ->wasSentTo($notifiable)
        ->inThePastMinutes(60);
}
```

You can fully customize which notifications get logged and how they get logged.
