You can install the package via composer:
composer require wpzag/laravel-notifications
Create notifications table
php artisan notifications:table
php artisan migrate
- First we need to use the Notifiable trait in the user model:
use Wpzag\LaravelNotifications\Traits\Notifiable;
class User extends Authenticatable
{
use Notifiable;
}
- Then we need to create a notification class that extends BaseNotification class:
<?php
namespace App\Notifications;
use Wpzag\LaravelNotifications\BaseNotification;
class TestNotification extends BaseNotification
{
public function getTranslationParams() : array
{
return [
'user'=>'user.name',
];
}
public function getNotificationLink() : string
{
return 'users/'.$this->relations['user']['id'];
}
}
- Create notifications.php in lang/en and add entry in translation file:
return [
'user_updated' => ':user has updated his profile',
'titles' => [ 'user_updated' => 'User Updated' ],
]
- Notify the user
User::first()->notify(
TestNotification::create(
key: 'user_updated',
relations: ['user' => User::first()],
data: ['random' => 'data']
));
- Then we get the notifications with:
use Wpzag\LaravelNotifications\LaravelNotifications;
LaravelNotifications::getPaginatedNotifications();
composer test
Please see CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING for details.
Please review our security policy on how to report security vulnerabilities.
The MIT License (MIT). Please see License File for more information.