syropian/laravel-notification-channel-throttling 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

syropian/laravel-notification-channel-throttling

最新稳定版本:v1.0.1

Composer 安装命令:

composer require syropian/laravel-notification-channel-throttling

包简介

Throttle notifications on a per-channel basis

README 文档

README

Laravel Notification Channel Throttling

🚦 Laravel Notification Channel Throttling

Throttle your Laravel notifications on a per-channel basis

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

Introduction

When sending notifications through multiple channels (say email and SMS), you may want to throttle the number of notifications sent through a specific channel. For example, you could limit the number of SMS notifications sent to a user to 1 per day, and limit emails to 5 per day. This package allows you to configure this easily directly in your notification classes.

Installation

You can install the package via composer:

composer require syropian/laravel-notification-channel-throttling

Usage

  1. Ensure the notification you want to throttle implements Syropian\LaravelNotificationChannelThrottling\Contracts\ThrottlesChannels.
  2. Implement the throttleChannels method. This method should return an array of channels to throttle, and the configuration for each channel. To omit a channel from throttling either omit the channel from the array, or set the value to false.
use Illuminate\Notifications\Notification;
use Syropian\LaravelNotificationChannelThrottling\Contracts\ThrottlesChannels;

class ExampleNotification extends Notification implements ThrottlesChannels {
    // ...

    public function throttleChannels(object $notifiable, array $channels): array
    {
        /**
         * Throttle the mail channel, so that only one
         * email notification is sent every 15 minutes
         */
        return [
            'mail' => [
                'maxAttempts' => 1,
                'decaySeconds' => 900,
            ],
            'database' => false,
        ];
    }
}

Scoping the rate limiter

By default, the rate limiter instance used to throttle is automatically scoped to the notification and channel. If you would like to further scope the rate limiter, you may pass a key to the channel configuration.

public function __construct(public Post $post) {}

public function throttleChannels(object $notifiable, array $channels): array
{
    return [
        'mail' => [
            'key' => $notifiable->id . ':' . $this->post->id,
            'maxAttempts' => 1,
            'decaySeconds' => 900,
        ],
        'database' => false,
    ];
}

In this example we're rate limiting the mail channel, and we're scoping it to a specific combination of a user and a post.

Testing

composer test

Credits

License

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

统计信息

  • 总下载量: 2.54k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 9
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 9
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-11-19