承接 zachflower/ignorable-observers 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

zachflower/ignorable-observers

最新稳定版本:v0.2.0

Composer 安装命令:

composer require zachflower/ignorable-observers

包简介

Dynamically disable/enable Laravel's Eloquent model observers

README 文档

README

Code Climate build Packagist

Dynamically disable/enable Laravel's Eloquent model observers. This library provides the ability to temporarily disable observable events for Eloquent models. For example, temporarily disable observers that kick off emails, push notifications, or queued calculations when performing a large number of database inserts or updates.

Installation

Install using composer:

composer require zachflower/ignorable-observers

Usage

To give an Eloquent model the ability to temporarily ignore observers, simply add the IgnorableObservers trait:

<?php namespace App;

use Illuminate\Database\Eloquent\Model;
use IgnorableObservers\IgnorableObservers;

class ExampleModel extends Model {
  use IgnorableObservers;
}

Then, call the ignoreObservableEvents() static method to ignore all observers for that model:

ExampleModel::ignoreObservableEvents();

The ignoreObservableEvents() method also accepts an array of observers to be ignored. For example, the following line would ignore only the saved and created observers:

ExampleModel::ignoreObservableEvents(['saved', 'created']);

To stop ignoring a model's observers, call the unignoreObservableEvents() static method:

ExampleModel::unignoreObservableEvents();

The unignoreObservableEvents() method also accepts an array of observers to unignore, giving you total control over which observers to enable and disable:

ExampleModel::unignoreObservableEvents(['saved']);

Example

The following example ignores any saved and created observers for the ExampleModel, inserts 100 rows into the database, and then "unignores" those observers when the operation is completed:

ExampleModel::ignoreObservableEvents('saved', 'created');

for ( $i = 0; $i <= 100; $i++ ) {
  ExampleModel::create([
    'data' => $i
  ]);
}

ExampleModel::unignoreObservableEvents();

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

License

Ignorable Observers is an open-sourced library licensed under the MIT license.

统计信息

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

GitHub 信息

  • Stars: 24
  • Watchers: 2
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-02-07