You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
2.7 KiB
2.7 KiB
Laravel Queue Notifer Example
This is a sample project for implementing realtime feature for laravel using these packages:
- Laravel websockets (https://github.com/beyondcode/laravel-websockets)
- Laravel Echo (https://github.com/laravel/echo)
- Noty JS (https://ned.im/noty)
Features
This project is just an example impelemntation, so we will have:
- A basic job run for 5 seconds in the background, then notify all users after done (without refreshing the browser).
- A basic job run for 5 seconds in the background, then notify only the current user (privately, also without refreshing the browser).
Getting Started
Server Requirements
- PHP ^7.2 (And meet the laravel 7.x server requirements).
- MySQL or MariaDB or Sqlite database.
How to Install
- Clone the repo:
$ git clone https://github.com/nafiesl/laravel-queue-notifier-example.git $ cd laravel-queue-notifier-example$ composer install$ cp .env.example .env$ php artisan key:generate- Create a MySQL/MariaDB/Sqlite database for this project
- Set the database credential on
.envfile $ php artisan migrate$ php artisan serve- Open a new terminal tab
$ php artisan queue:work - Open a new terminal tab (again)
$ php artisan websockets:serve - The project is ready to use.
How to Use
- Open the web page via browser
http://127.0.0.1:8000(the given link on How to Install step #9) - Register as a new user:
John(we will be redirected to the/homeroute) - Open a new browser with incognito/private mode, go to
http://127.0.0.1:8000 - Register as a new different user:
David(we will be redirected to the/homeroute as well) - When John hits the Run a long job button
- John will be redireted back to home
- John will get a notifier message on the bottom right
Please wait, your request is processing.... - Don't refresh the page, just wait...
- After 5 seconds, both John and David will get a notifier message
Long run job done after 5 seconds - John and David get the notifier, because this is a public channel for all users.
- When David hits the Run a long job button, same behavior on point #5 happen for David.
- When David hits the Run a long private job button
- David will be redirected back to home
- Davil will get a notifier message on the bottom right
Please wait, your request is processing.... - Don't refresh the page, just wait...
- After 5 seconds, both David will get a notifier message
Long run private job (for '...') done after 5 seconds - John will not get the notifier, because this is a private channel for David.
License
This sample project is a free and open-source under MIT license.