# [Usage](../../../usage.md) > [Components](../basics.md) > [Others](../basics.md) > Notification

The user Notification is both a component and a complete module. Enabling the module will spawn in the headbar of the UI a button to open the notification panel for the user, and the Notification tab in the user profile. Use it for persistent per-user inbox messages with polling and e-mail fallback; use [Alert](../visuals/alert.md) with `session_messages` for one-shot page feedback, not for long-lived user targeting. Then, you can send users notifications with:

```php
{!!
    \KFramework\Components\Users\Notification::make('Notification title')
        ->setContent('This is the notification content')
!!}
```

**End-to-end example:** maintenance notice to a team with deep link.
```php
// Blade preview:
{!!
    \KFramework\Components\Users\Notification::make('Maintenance tonight')
        ->setContent('The platform will be offline from 22:00 to 23:00.')
        ->setUrl('/status')
!!}

// Controller:
use KFramework\Components\Users\Notification;

Notification::make('Maintenance tonight')
    ->setContent('The platform will be offline from 22:00 to 23:00.')
    ->setUrl('/status')
    ->setUsers([1, 4, 7])
    ->send();
```

---
## Usage

You must first enable the notification module `'user_notifications' => true` in `config/k-framework/modules.php`.  
The module `'user_profile'` must be enabled too in order for the user notification to work.

- Blade:
```php
{!! \KFramework\Components\Users\Notification::make() !!}
```
- Controller:
```php
\KFramework\Components\Users\Notification::make()
```

A notification for the user can be created as this:

```php
$notification = Notification::make('This is a notification')
                    ->setContent('Here I will say the message to the user')
                    ->setUsers([1,4,7]);
```

This will create a notification for the users with id `1`, `4` and `7`: `->setUsers()` method receive an array of users ids.
Otherwise you can specify the user emails:

```php
$notification = Notification::make('This is a notification')
                    ->setContent('Here I will say the message to the user')
                    ->setEmails(['first@email.com','second@email.com']);
```

Or both:

```php
$notification = Notification::make('This is a notification')
                    ->setContent('Here I will say the message to the user')
                    ->setUsers([1,4,7])
                    ->setEmails(['first@email.com','second@email.com']);
```

This will create notification both for the user ids specified and the email specified.

Once the notification is formed and edited, you can send it:

```php
$notification->send();
```

Or you can directly send at the moment of creation:

```php
Notification::make('This is a notification')
  ->setContent('Here I will say the message to the user')
  ->setUsers([1,4,7])
  ->send();
```

_NOTE:_ if the same notification is assigned to a user id which has the same email of the emails indicated, it will be created just one notification assigned to designated email.  
_NOTE 2:_ the notification panel shows the last 20 notification, unread notifications take priority in order.  
_NOTE 3:_ if the module of notification is enabled, the notification will be delivered in real time to the user, with 3 seconds of polling.

In `config/k-framework/users.php` you will also find:
```php
'notifications' => [
  'send_email_at_creation' => false,
  'email_template_view' => 'kfw::ui.user.email_notification', // default: 'kfw::ui.user.email_notification',
  ]
```

If `send_email_at_creation` is set to `true` then the user will receive an email from the default mailer when a new notification is sent, the email will contain the title and message of the notification. If there is no user registered with the email, the notification will still be created and registered for that email, and the email of the notification will still be sent. 

The `email_template_view` is the blade view of default that will be sent via email. This is the example content:
```bladehtml
<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
<body>
  <div class="container">
    {{ __('kfw::users.notifications.hello') }},<br>
    {{ __('kfw::users.notifications.you_have_a_new_notification') }}:
    <div class="notification">
      @if(!empty($name))
      <div class="title">{!! $name ?? '' !!}</div>
      @endif
      @if(!empty($content))
      <div class="content">{!! $content ?? '' !!}</div>
      @endif
      @if(!empty($url))
      <div class="url"><a href="{{ $url }}">➥</a></div>
      @endif
    </div>
    <div class="end-message">{{ __('kfw::users.notifications.preference_update_message') }}. {{ __('kfw::users.notifications.privacy_policy_message') }} <a href="{{ config('k-framework.guest.privacy_policy_url') ?? config('app.url') }}">link</a>.</div>
  </div>
</body>
</html>
```

You can add a Privacy Policy URL by editing the config `'privacy_policy_url'` in `config/k-framework/guest.php`.

---
## Standard attributes

- `uuid`
- `id`
- `name`
  - Title of the notification.
- `url`
  - Create a button on the notification that redirects to the URL.
- `content`
  - Add the notification message. Use `name` for the title line and `content` for the body; targeting is done via `users`/`emails` below.

See their usage and description [here](../basics.md).

---
## Component-specific attributes

### `users` | `->setUsers()`
Set the users ids to send the notification.

| Types   | Default |
|---------|---------|
| `array` | `null`  |


### `emails` | `->setEmails()`
Set the emails to register the notification.

| Types   | Default |
|---------|---------|
| `array` | `null`  |

---
## Component methods

### `->send()`
This method will send the notification.

## See also
- [Components basics](../basics.md)
- [Alert](../visuals/alert.md)
- [content](../shared_attributes/content.md), [url](../shared_attributes/url.md), [name](../shared_attributes/name.md)
- [session_messages](../../utilities/frontend/session_messages.md)