{"id":15657062,"url":"https://github.com/zachflower/ignorable-observers","last_synced_at":"2025-04-30T08:21:56.433Z","repository":{"id":57089002,"uuid":"81143655","full_name":"zachflower/ignorable-observers","owner":"zachflower","description":"Dynamically disable/enable Laravel's Eloquent model observers.","archived":false,"fork":false,"pushed_at":"2020-01-28T17:50:52.000Z","size":14,"stargazers_count":24,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-14T22:02:38.308Z","etag":null,"topics":["eloquent","laravel","laravel-package","php"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zachflower.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-02-06T23:16:25.000Z","updated_at":"2022-02-18T19:01:25.000Z","dependencies_parsed_at":"2022-08-20T16:00:37.655Z","dependency_job_id":null,"html_url":"https://github.com/zachflower/ignorable-observers","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zachflower%2Fignorable-observers","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zachflower%2Fignorable-observers/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zachflower%2Fignorable-observers/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zachflower%2Fignorable-observers/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zachflower","download_url":"https://codeload.github.com/zachflower/ignorable-observers/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251666682,"owners_count":21624352,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["eloquent","laravel","laravel-package","php"],"created_at":"2024-10-03T13:05:11.659Z","updated_at":"2025-04-30T08:21:56.403Z","avatar_url":"https://github.com/zachflower.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Ignorable Observers\n\n[![Code Climate](https://codeclimate.com/github/zachflower/ignorable-observers/badges/gpa.svg)](https://codeclimate.com/github/zachflower/ignorable-observers) [![build](https://img.shields.io/endpoint.svg?url=https%3A%2F%2Factions-badge.atrox.dev%2Fzachflower%2Fignorable-observers%2Fbadge\u0026label=build)](https://actions-badge.atrox.dev/zachflower/ignorable-observers/goto) [![Packagist](https://img.shields.io/packagist/v/zachflower/ignorable-observers.svg)]()\n\nDynamically 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.\n\n## Installation\n\nInstall using composer:\n\n```\ncomposer require zachflower/ignorable-observers\n```\n\n## Usage\n\nTo give an Eloquent model the ability to temporarily ignore observers, simply add the `IgnorableObservers` trait:\n\n```php\n\u003c?php namespace App;\n\nuse Illuminate\\Database\\Eloquent\\Model;\nuse IgnorableObservers\\IgnorableObservers;\n\nclass ExampleModel extends Model {\n  use IgnorableObservers;\n}\n```\n\nThen, call the `ignoreObservableEvents()` static method to ignore all observers for that model:\n\n```php\nExampleModel::ignoreObservableEvents();\n```\n\nThe `ignoreObservableEvents()` method also accepts an array of observers to be ignored. For example, the following line would ignore only the `saved` and `created` observers:\n\n```php\nExampleModel::ignoreObservableEvents(['saved', 'created']);\n```\n\nTo stop ignoring a model's observers, call the `unignoreObservableEvents()` static method:\n\n```php\nExampleModel::unignoreObservableEvents();\n```\n\nThe `unignoreObservableEvents()` method _also_ accepts an array of observers to unignore, giving you total control over which observers to enable and disable:\n\n```php\nExampleModel::unignoreObservableEvents(['saved']);\n```\n\n### Example\n\nThe 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:\n\n```php\nExampleModel::ignoreObservableEvents('saved', 'created');\n\nfor ( $i = 0; $i \u003c= 100; $i++ ) {\n  ExampleModel::create([\n    'data' =\u003e $i\n  ]);\n}\n\nExampleModel::unignoreObservableEvents();\n```\n\n## Contributing\n\n1. Fork it\n1. Create your feature branch (`git checkout -b my-new-feature`)\n1. Commit your changes (`git commit -am 'Add some feature'`)\n1. Push to the branch (`git push origin my-new-feature`)\n1. Create new [Pull Request](https://github.com/zachflower/ignorable-observers/compare)\n\n## License\n\nIgnorable Observers is an open-sourced library licensed under the MIT license.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzachflower%2Fignorable-observers","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzachflower%2Fignorable-observers","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzachflower%2Fignorable-observers/lists"}