wpzag/laravel-notifications

This is my package laravel-notifications

v1.0.4 2022-08-05 22:23 UTC

This package is auto-updated.

Last update: 2024-04-06 01:38:05 UTC


README

Installation

You can install the package via composer:

composer require wpzag/laravel-notifications

Create notifications table

php artisan notifications:table
php artisan migrate

Usage

  1. First we need to use the Notifiable trait in the user model:
    use Wpzag\LaravelNotifications\Traits\Notifiable;
    class User extends Authenticatable
    {
        use Notifiable;
     }
  1. 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'];
		}
	}
  1. 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' ],
]
  1. Notify the user
   User::first()->notify(
         TestNotification::create(
                 key: 'user_updated',
                 relations: ['user' => User::first()],
                 data: ['random' => 'data']
    ));
  1. Then we get the notifications with:
  use Wpzag\LaravelNotifications\LaravelNotifications;
  LaravelNotifications::getPaginatedNotifications();

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.