wpzag / laravel-notifications
This is my package laravel-notifications
v1.0.4
2022-08-05 22:23 UTC
Requires
- php: ^8.1
- illuminate/contracts: ^9.0
- spatie/laravel-package-tools: ^1.9.2
- staudenmeir/eloquent-json-relations: ^1.1
Requires (Dev)
- nunomaduro/collision: ^6.0
- orchestra/testbench: ^7.0
- pestphp/pest: ^1.21
- pestphp/pest-plugin-laravel: ^1.1
- phpunit/phpunit: ^9.5
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
- 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();
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.