Download the PHP package ivfuture/laravel-event-notification without Composer
On this page you can find all versions of the php package ivfuture/laravel-event-notification. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download ivfuture/laravel-event-notification
More information about ivfuture/laravel-event-notification
Files in ivfuture/laravel-event-notification
Package laravel-event-notification
Short Description Laravel package to send notification through events.
License MIT
Informations about the package laravel-event-notification
Laravel Event Notification
This package provides an easy way to integrate notifications with Laravel 6, Redis and socket.io . After the installation the user will be able to receive real time notification.
Here are some examples:
Installation
You can install this package via composer using:
To register the package you have to add the service provider in your file:
Now you should publish the migration with:
After the migration have been published you can create the tables by running the migrations:
Next, we have to install the npm packages:
Settings
First of all, you have to edit your file to tell Laravel to use the correct .
If you are using an older version of Laravel you may skip the next step. You have to edit your file and comment the line that is adding a prefix to redis:
Starting the servers
Now all you have to do is start the servers.
Usage
After you've installed the package and done all the settings it's time to integrate the notifications in your project.
First, don't forget to import the trait at the top of your file.
Subscribe to channels notification
In your Controller constructor you must subscribe to the channels. You can do this by using 's function . It will search in table for channels and will automatically subscribe to them.
Send a notification
There is also a convenient function for sending a notification:
This will save the notification into the database and will send an event with all its data.
Get notifications from database
You can get the notifications from database:
This will provide us with notifications grouped by time categories like: , , or .
Receive the notification in view
To receive real time notifications you must follow this 3 steps:
1 - Import socket.io library
2 - Create a Socket object.
Note: By default the server wil listen for port 3000. You can change that by editing the value of in your file.
3 - Listen to the channel from which notification was sent.
Note: If you have many channels, you must listen to all of them.
Example:
And finally, don't forget to check if the user is the receiver of notification.