monooso/
unobserve
g4t.io

Mute and Unmute Model Observers With Unobserve

18 views 83 stars by Paul Redmond

Mute and unmute Laravel observers at will.

README from monooso/unobserve Open on GitHub →

Unobserve

About Unobserve

When testing Laravel applications, we frequently need to "silence" events, so as not to trigger additional side-effects. Laravel's Event::fake method is useful, but muting a specific model observer is still problematic.

Unobserve takes care of that, making it easy to mute and unmute an observer at will.

Requirements and installation

Unobserve supports only the latest major version of Laravel. See composer.json for the exact version requirements.

Install it using Composer:

composer require monooso/unobserve

Usage

First, add the CanMute trait to your observer class.

<?php

namespace App\Observers;

use Monooso\Unobserve\CanMute;

class UserObserver
{
    use CanMute;
}

You can now mute and unmute your observer as needed:

UserObserver::mute();
UserObserver::unmute();

Mute options

Mute all observer events:

UserObserver::mute();

Mute specific observer events:

UserObserver::mute('creating');
UserObserver::mute(['creating', 'created']);

Local development

Unobserve is very stable at this point. If you have any feature ideas please open an issue before doing any work.

Development and testing happen entirely inside Podman containers, driven by the ./dev script. You do not need to install PHP, Composer, or any project dependencies on your machine.

The dev helper script builds a disposable PHP + Composer image for the PHP version you name, mounts your working tree into it, and runs your command. Any changes to composer.json and composer.lock are written back to your disk so they can be committed.

Prerequisites

Podman 5.x or later.

Common tasks

The dev script always accepts the target PHP version as the first argument. The first time you run a command with a given PHP version, it builds the image automatically.

Command Purpose
./dev 8.3 Open a shell on PHP 8.3
./dev 8.3 test Run the test suite
./dev 8.3 lint Run Laravel Pint
./dev 8.3 composer install Install dependencies from the lock file
./dev 8.3 composer update Re-resolve dependencies (rewrites composer.lock)
./dev 8.3 composer outdated List outdated packages
./dev 8.3 php -v Run any command in the container
./dev build 8.3 Rebuild the image for a version

Run ./dev --help for the full reference.

Upgrading PHP or Laravel

  1. Create a branch.

  2. Edit composer.json to widen the relevant constraints, e.g. "php": "^8.3" and "illuminate/support": "^13.0".

  3. Re-resolve dependencies against the target PHP version:

    ./dev 8.3 composer update
    
  4. In the event of a conflict, investigate and iterate:

    ./dev 8.3 composer why-not laravel/framework 13.0.0
    ./dev 8.3 composer require illuminate/support:"^13.0" --no-update
    ./dev 8.3 composer update
    
  5. Run the tests and linter:

    ./dev 8.3 test
    ./dev 8.3 lint
    
  6. Commit composer.json and composer.lock.

Each PHP version keeps its own dependency cache, so several versions can be tested side by side (e.g. ./dev 8.2 test, ./dev 8.3 test) without interfering with each other.

License

Unobserve is open source software, released under the MIT license.

More from the ecosystem

durable-workflow/
workflow
g4t.io
9 1,292

Durable Workflow: Long-Running Workflows for Laravel

Embedded durable workflow runtime and orchestration engine for Laravel applications.

durable-workflow/workflow via Laravel News
packstub/
session-replay
g4t.io
14 52

Session Replay for Laravel: Self-Hosted Browser Recordings

Session replay for Laravel: record what a person did in the browser with rrweb, keep the recording on your own disk and database, and watch it behind a gate you define — masked inputs by default, errors, failed Livewire requests and web vitals marked on the timeline, a link to the replay in every log line. packstub/filament-session-replay adds the sessions to a Filament panel.

packstub/session-replay via Laravel News
cyberwizard-dev/
schedule-catchup
g4t.io
17

Replay Missed Laravel Scheduled Tasks With Schedule Catchup

Schedule Catchup replays missed Laravel scheduled tasks after downtime, with opt-in recovery, bounded retries, and access to the original scheduled date.

cyberwizard-dev/schedule-catchup via Laravel News