New Notification System using Laravel 5.7
In this section, we are going to learn a new notification system. We will use Laravel 5.7 to do this. We will use various notification systems such as mail, markdown, slack, database, broadcast, and SMS to send the notification. Here we will provide the example of an email notification system. Using the new notification system, we can easily send notification to all users at the same time.
We can use various things to send the notification in Laravel, such as SMS, mail, slack, or database. Using the Laravel artisan command, we can simply create notification. The customization of notification is very simple such as mail body, mail subject, mail action, etc. If we are working on a big project such as e-commerce, at that time, we need to use notification to send the notification to the clients. In the form of order place receipt, payment receipt, invoice, etc, the notification can be sent.
In our Laravel application, we are going to create an email notification, and then we will send it to a particular user. After sending, we will use our database and save it. In order to create notification, the step by step process is described as follows:
In this step, we are going to Download Laravel 5.7. In our application, we require a fresh version of Laravel 5.7. So the following command will be used to get it. For this, we will use our terminal and run the following command like this:
In this step, we are going to Create Database Table. We will use the Laravel 5 artisan to create a new database table named "notifications". The command to create a table is described as follows:
In this step, we are going to Create Notification. We will use Laravel 5 artisan to create MyFirstNotification. For this, we will use the command, which is described as follows:
When we successfully execute the above command, a new folder named "Notification" will be created in the app folder. Now we will make some changes, which are described as follows:
In this step, we are going to Create Route. We need to send notifications to a user that's why we will create route. For this, we will use our file named "routes/web.php" and put the following code into it like this:
In this step, we are going to Create Controller. So we will create a new controller named HomeController, which is used to handle the generatePDF method of route. For this, we will add the following code:
When we run the above command, we are able to send the first notification to the user. For this, we will run the following command like this:
Now we can use our browser to open the bellow URL:
We can also use the following command to send notification like this:
The sent notification can be got by using the following command like this:
When we run this command, the following output will be generated: