Author - StudySection Post Views - 264 views

Notifications In Laravel

Laravel provides support to send notifications via different channels. The main purpose of the notification in Laravel is to notify the users if something can happen in the application. For example, if we are working on the sale-purchase application, then on-sold we might send a notification to the seller of the vehicle and buyer of the vehicle via email and SMS.

Generating Notifications:

Command to create a notification class for any feature.
php artisan make:notification {{VehicleSold}}

This command creates a class in the app/Notification directory. Each class contains via to send notification either mail or fcm (push notification) or both.

Sending Notifications:

Notifiable Trait: We can send a notification with a notifiable trait or notification facade.
Notifiable is used when we send notifications to a single user.

use App\Notifications\VehicleSold;
$user->notify(new VehicleSold($data));

Notification Facade: You can use a notification facade to send notifications to multiple users. Like sending vehicle sold notifications to all users of the company. To send the notification, you can use the send method by passing a list of the users of the company.

use Illuminate\Support\Facades\Notification;
Notification::send($users, new VehicleSold($data));


* Get the notification's mail representation.
* @param mixed $notifiable
* @return \Illuminate\Notifications\Messages\MailMessage
public function toMail($notifiable)
return (new MailMessage)
->greeting('Hello '.$notifiable->name.'!')
->subject('Test Email')
->line('Thank you for using our application!');
* To send event alongwith notification
* @param mixed $notifiable
* @return \App\Events\VehicleSold
public function toEvent($notifiable)
Log::info('In VehicleSold notification toEvent method');
return new ListingSold([data => $data ]);
public function toFcm($notifiable)

Knowledge of .NET is quite rewarding in the IT industry. If you have got some skills in the .NET framework then a .NET Certification Exams from StudySection can prove to be a good attachment with your resume. You can go for a foundation level certificate as well as an advanced level certificate in the .NET framework.

Leave a Reply

Your email address will not be published. Required fields are marked * cratosroyalbet betwoon grandpashabet grandpashabet giriş deneme bonusu veren siteler casino siteleri