think.studio/laravel-periodic-notice 问题修复 & 功能扩展

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

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

think.studio/laravel-periodic-notice

最新稳定版本:1.4.0

Composer 安装命令:

composer require think.studio/laravel-periodic-notice

包简介

Send your periodical series to user as batch using notifications.

README 文档

README

Packagist License Packagist Version Total Downloads Build Status Code Coverage Scrutinizer Code Quality

Send your periodical series to user as batch using notifications.

Installation

Install the package via composer:

composer require think.studio/laravel-periodic-notice

You can publish the assets file with:

php artisan vendor:publish --provider="PeriodicNotice\ServiceProvider" --tag="config"
php artisan vendor:publish --provider="PeriodicNotice\ServiceProvider" --tag="lang"

To disable default migrations add this code to app service provider:

\PeriodicNotice\PeriodicNoticeManager::ignoreMigrations()

Usage

use PeriodicNotice\Concerns\HasPeriodicNotice;
use PeriodicNotice\Contracts\NotificationReceiver;
use PeriodicNotice\PeriodicNoticeDirector;

class User extends \Illuminate\Foundation\Auth\User implements NotificationReceiver
{
    use Notifiable;
    use HasPeriodicNotice;

    public function periodicNoticeDirector(string $group = 'default'): PeriodicNoticeDirector
    {
        $dayInSeconds = 60 * 60 * 24;

        return PeriodicNoticeDirector::defaults($group)
                                     ->usePeriodType($this->periodic_notification_type)
                                     ->usePeriodTypesMap([
                                         'every_day'  => round($dayInSeconds),
                                         'every_week' => round($dayInSeconds * 7),
                                     ])
                                     ->useQueryToGetEntries(Post::class);
    }

    public function scopeWithNotificationPeriodType(Builder $query, string $type, string $group = 'default')
    {
        $query->where('periodic_notification_type', '=', $type);
    }
}
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use PeriodicNotice\Concerns\InPeriodicNotice;
use PeriodicNotice\Contracts\SendableEntity;
use PeriodicNotice\Tests\Fixtures\Factories\PostFactory;

class Post extends Model implements SendableEntity
{
    use InPeriodicNotice;

    public function scopeReleasedAfter(Builder $query, \DateTimeInterface|string $dateTime, string $group)
    {
        $query->where('published_at', '>=', $dateTime);
    }
}

Manual call

php artisan periodic-notice:send:batch every_day \\App\\Models\\User
# or use morph alias
php artisan periodic-notice:send:batch every_day user
# use custom group
php artisan periodic-notice:send:batch every_day user -G custom_group

More appropriate way is using cron schedule

$schedule->command('periodic-notice:send:batch every_day user')
          ->dailyAt('18:00');

Credits

  • Think Studio

统计信息

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

GitHub 信息

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

其他信息

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