agrodata/notificationapi
最新稳定版本:1.2.1
Composer 安装命令:
composer require agrodata/notificationapi
包简介
Pacote para utilização do serviço de ptax do Banco do Brasil
README 文档
README
Notification-api for Laravel
Package created to use the notification-api Service (https://www.notificationapi.com/) in Laravel projects
Official Doc for Notification Api: https://docs.notificationapi.com/
Installation
To get the latest version of `notificationapi-laravel` on your project, require it from "composer":
$ composer require nairanomura/notificationapi-laravel
Or you can add it directly in your composer.json file:
{
"require": {
"nairanomura/notificationapi-laravel": "1.0"
}
}
Config
Register the provider directly in your app configuration file config/app.php:
'providers' => [
// ...
NairanOmura\NotificationApi\NotificationApiServiceProvider::class,
]
The following lines will be auto added in config/services.php by provider.
return [
//...
'notification-api' => [
'key' => env('NOTIFICATION_API_KEY'),
'secret' => env('NOTIFICATION_API_SECRET'),
]
];
So add the following environment variables in .env file to finish a configuration:
#.env
NOTIFICATION_API_KEY=clientID
NOTIFICATION_API_SECRET=clientSecret
This keys was offered by notification api after register an account
Using
Use Artisan to create a notification:
php artisan make:notification SomeNotification
Return [notification-api] in the public function via($notifiable) method of your notification:
public function via($notifiable)
{
return ['notification-api'];
}
Add the method public function toNotificationApi($notifiable) to your notification:
//...
public function toNotificationApi($notifiable)
{
return [
"notificationId" => "notification_example",
"user" => [
"id" => $notifiable->getAttribute('id'),
"email" => $notifiable->getAttribute('email'),
],
"mergeTags" => [
"userName" => auth()->user()->name,
"clickAction" => config('app.env')."/example"
]
];
}
example of notification send
*Attention: To call notification by the user model, the User model must be "Notifiable" Trait
class User extends Authenticatable
{
use Notifiable;
//...
#notify one user
$user->notify((new SomeNotification(..)));
#notify multiple users
Notification::send($users, new SomeNotification(..);
Extra: Helpers
After install and configure we can use the library calling the helper notification_api or class NotificationApiService
Example:
$data = [
"notificationId" => "order_tracking",
"user" => [
"id" => "example@mail.com",
"email" => "example@mail.com",
"number" => "+15005550006"
],
"mergeTags" => [
"item" => "Krabby Patty Burger",
"address" => "124 Conch Street",
"orderId" => "1234567890"
]
];
$result = notification_api($data);
#or
$result = (new NotificationApiService)->send($data)
统计信息
- 总下载量: 1.37k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-02-08