> For the complete documentation index, see [llms.txt](https://learnphp.gitbook.io/learnphp/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://learnphp.gitbook.io/learnphp/learn-lavarel/api-rest-with-laravel-5.6-passport-authentication-send-notifications-with-queues-on-redis-part-5.md).

# API Rest with Laravel 5.6 Passport Authentication — Send Notifications with Queues on Redis (Part 5)

https\://medium.com/modulr/api-rest-with-laravel-5-6-175eea5db3e8

We learning how to send Notifications with management to queues using Redis. In this tutorial we will use the Notifications created previously in the previous tutorials.![Image for post](https://miro.medium.com/max/60/1*5leMpSOqRxxF-DsmtuR48g.jpeg?q=20)![Image for post](https://miro.medium.com/max/2400/1*5leMpSOqRxxF-DsmtuR48g.jpeg)[https://www.vecteezy.com](https://www.vecteezy.com/)

—[ Install Redis](https://medium.com/modulr/api-rest-with-laravel-5-6-175eea5db3e8#03da)\
— [Config Enviroment](https://medium.com/modulr/api-rest-with-laravel-5-6-175eea5db3e8#245b)\
—[ Install Redis Driver](https://medium.com/modulr/api-rest-with-laravel-5-6-175eea5db3e8#cbf4)\
—[ Run the Queue Worker](https://medium.com/modulr/api-rest-with-laravel-5-6-175eea5db3e8#70b4)\
—[ Install andConfigure supervisor](https://medium.com/modulr/api-rest-with-laravel-5-6-175eea5db3e8#57b5)

## Step 1 Install Redis <a href="#id-03da" id="id-03da"></a>

In first step, we install Redis for this I let you two great tutorials for MacOsx and Linux.

Ubuntu 16.04

<https://www.digitalocean.com/community/tutorials/how-to-install-and-configure-redis-on-ubuntu-16-04>

MacOsx

<https://medium.com/@petehouston/install-and-config-redis-on-mac-os-x-via-homebrew-eb8df9a4f298>![Image for post](https://miro.medium.com/max/60/1*ODEhpzaUmQnzu-Xd4j6CWA.png?q=20)

![Image for post](https://miro.medium.com/max/1695/1*ODEhpzaUmQnzu-Xd4j6CWA.png)

## Step 2 Config Enviroment <a href="#id-245b" id="id-245b"></a>

In this step we will config our `.env` file, add **redis** into *QUEUE\_DRIVER* variable also change the REDIS\_ variables, finally config the e-mail service. I recomend [Mailtrap](https://mailtrap.io/) to test.

```
QUEUE_DRIVER=redisREDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=user
MAIL_PASSWORD=password
MAIL_ENCRYPTION=null
```

## Step 3 Install Redis Driver <a href="#cbf4" id="cbf4"></a>

We need install Redis driver in to the project, using bellow command, So open your terminal or command prompt and run bellow command:

```
composer require predis/predis
```

## Step 4 Run the Queue Worker <a href="#id-70b4" id="id-70b4"></a>

To test the queues in your local machine need run the queue worker, so run bellow command:

```
php artisan queue:work
```

You see in the terminal when the notification is processed![Image for post](https://miro.medium.com/max/60/1*LWUzyJ5sbryH5oGhHMe95w.png?q=20)![Image for post](https://miro.medium.com/max/2020/1*LWUzyJ5sbryH5oGhHMe95w.png)

## Step 5 Install and Configure supervisor <a href="#id-57b5" id="id-57b5"></a>

> This step is used for production mode in your Linux server.

Install supervisor with the next command:

```
sudo apt-get install supervisor
```

Enter to folder `config.d`

```
cd /etc/supervisor/conf.d
```

Create config file

```
sudo nano laravel-worker.conf
```

Into the file write the next code lines

```
[program:laravel-worker]process_name=%(program_name)s_%(process_num)02dcommand=php /var/www/project_name/artisan queue:work redis --sleep=3 --tries=3autostart=trueautorestart=trueuser=www-datanumprocs=8redirect_stderr=truestdout_logfile=/var/www/project_name/storage/logs/worker.logstopwaitsecs=3600
```

Starting Supervisor

Once the configuration file has been created, you may update the Supervisor configuration and start the processes using the following commands:

```
sudo supervisorctl rereadsudo supervisorctl updatesudo supervisorctl start laravel-worker:*
```

> Now we are ready to run our example so run bellow command to quick run:

```
php artisan serve
```

## Tests <a href="#a30c" id="a30c"></a>

Now, we can simple test by rest client tools (Postman), So I test it and you can see below screenshots.

> In this api you have to set two header as listed below:

```
Content-Type: application/json
X-Requested-With: XMLHttpRequest
```

Signup![Image for post](https://miro.medium.com/max/60/1*dmTS5yefQ7QQ6kOrIYLvaw.png?q=20)![Image for post](https://miro.medium.com/max/1274/1*dmTS5yefQ7QQ6kOrIYLvaw.png)

When create new account will receive a email with the link to activate account![Image for post](https://miro.medium.com/max/60/1*56KJaCViGGDR_UOwWKQYQA.png?q=20)![Image for post](https://miro.medium.com/max/1753/1*56KJaCViGGDR_UOwWKQYQA.png)

> Thanks for reading! I’m Alfredo Barrón, Feel free to connect with me via [Twitter](https://twitter.com/AlfredoBarronC).

Part 1. [Passport Authentication](https://medium.com/modulr/create-api-authentication-with-passport-of-laravel-5-6-1dc2d400a7f)\
Part 2. [Confirm account + notifications](https://medium.com/modulr/create-api-authentication-passport-in-laravel-5-6-confirm-account-notifications-part-2-5e221b021f07)\
Part 3. [Generate avatar](https://medium.com/modulr/api-rest-with-laravel-5-6-passport-authentication-generate-avatar-part-3-d92ec7935eff)\
Part 4. [Reset Password](https://medium.com/modulr/api-rest-with-laravel-5-6-passport-authentication-reset-password-part-4-50d27455dcca)\
**Part 5. Send Notifications with Queues on Redis**\
— Next up, Localization

### Resources <a href="#id-5231" id="id-5231"></a>

* [GitHub](https://github.com/modulr/api-laravel-passport)
* [Postman collections](https://documenter.getpostman.com/view/1657780/RW1ejGzL)

### References <a href="#id-998d" id="id-998d"></a>

* [Laravel Notifications](https://laravel.com/docs/5.6/notifications)
* [Laravel Queue](https://laravel.com/docs/5.7/queues)

## FUll CODE

{% file src="/files/-MDLPnXUTCvThsNP68S6" %}
