Looking to hire Laravel developers? Try LaraJobs

laravel-notifications maintained by wpzag

Description
This is my package laravel-notifications
Author
Last update
2022/08/06 00:23 (dev-main)
License
Downloads
13

Comments
comments powered by Disqus

Test Repo 🚧 🚧 🚧

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.