# Notifications

<figure><img src="/files/f6pxiNiaNfFQqcsTCUkH" alt=""><figcaption></figcaption></figure>

we are build a full notification system for you with multi provider like `mail`, `firebase`, `pusher`, `discord`, `slack`, `messagebird` and open the way to add more all of this working on queue and have a lot of helpers to make it easy to use this notification on your system

### Install

```bash
composer require queents/notifications-module
```

### Install Notifications Plugin

Add Module to `modules_statuses.json` if not exists

```json
{
    "Notifications": true
}
```

to install the notification's plugin by run this command

```bash
php artisan notifications:install
```

it will generate roles and permissions for notifications

after that we must get a firebase service file and attach the path to `FIREBASE_CREDENTIALS` on `.env` and generate a firebase database and set the url to `FIREBASE_DATABASE_URL` on `.env` to connect the firebase for realtime actions

Make a migration

```bash
php artisan migrate
```

Publish Assets

```bash
npm i & npm run build
```

OR

```bash
yarn & yarn build
```

### Setup Model for Notifications

to setup any model to get notification you must add our trait to handel that model

```php
<?php

namespace App\Models;

use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Laravel\Fortify\TwoFactorAuthenticatable;
use Laravel\Jetstream\HasProfilePhoto;
use Laravel\Sanctum\HasApiTokens;
use Spatie\Permission\Traits\HasRoles;
use Modules\Notifications\Traits\UseNotifications;

class User extends Authenticatable
{
    use HasApiTokens;
    use HasFactory;
    use HasProfilePhoto;
    use Notifiable;
    use TwoFactorAuthenticatable;
    use HasRoles;
    use UseNotifications;
    ...
```

and you must set the settings for `FCM` to get realtime notification

### Queue

the notification is run on queue, so you must run the queue worker to send the notifications

```bash
php artisan queue:work
```

### Create Template

to create a new template you can use template CRUD and make sure that the template key is unique because you will use it on every single notifications.

### Send Notification

to send a notification you must use our helper `SendNotification::class` like

```php
SendNotification::make($template->providers)
    ->template($template->key)
    ->findTitle($matchesTitle)
    ->replaceTitle($titleFill)
    ->findBody($matchesBody)
    ->replaceBody($titleBody)
    ->model(User::class)
    ->id(User::first()->id)
    ->privacy('private')
    ->fire();
```

where `$template` is select of template by key and `$matchesTitle` and `$matchesBody` is array of matches to replace on the template and `$titleFill` and `$titleBody` is array of values to replace the matches


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://queents.gitbook.io/vilt/plugins/notifications.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
