PHPackages                             fereydooni/laravel-observable - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. fereydooni/laravel-observable

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

fereydooni/laravel-observable
=============================

A robust and feature-rich observation system for dynamically observing Laravel objects

00PHP

Since Apr 24Pushed 1y ago1 watchersCompare

[ Source](https://github.com/Behnamfe76/laravel-observable)[ Packagist](https://packagist.org/packages/fereydooni/laravel-observable)[ RSS](/packages/fereydooni-laravel-observable/feed)WikiDiscussions master Synced today

READMEChangelogDependenciesVersions (1)Used By (0)

Laravel Observable
==================

[](#laravel-observable)

A robust and feature-rich observation system for dynamically observing Laravel objects (models, events, or other objects) and triggering callback functions using PHP attributes.

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require fereydooni/laravel-observable
```

After installing, publish the configuration file:

```
php artisan vendor:publish --provider="Fereydooni\LaravelObservable\DynamicObserverServiceProvider"
```

Run the migrations:

```
php artisan migrate
```

Usage
-----

[](#usage)

### Using Attributes

[](#using-attributes)

#### Observe Attribute

[](#observe-attribute)

Use the `Observe` attribute to define observation rules:

```
use Fereydooni\LaravelObservable\Attributes\Observe;

#[Observe(target: 'App\Models\User', event: 'created', callback: 'App\Services\Logger@log', priority: 10)]
class UserObserver
{
    public function handle($model)
    {
        // Custom logic when User model is created
    }
}
```

#### Observable Attribute

[](#observable-attribute)

Mark classes or methods as observable:

```
use Fereydooni\LaravelObservable\Attributes\Observable;

#[Observable(name: 'user_activity')]
class UserService
{
    public function createUser($data)
    {
        // This method can be observed
        return User::create($data);
    }
}
```

### Using the ObservationManager

[](#using-the-observationmanager)

```
use Fereydooni\LaravelObservable\ObservationManager;

// Get an instance of the manager
$manager = app(ObservationManager::class);

// Dynamically observe a model
$manager->observe('App\Models\User', 'updated', function($model) {
    \Log::info('User updated: ' . $model->id);
});

// Query observation logs
$logs = $manager->getObservationLogs('App\Models\User');

// Enable/disable specific observation
$manager->toggleObservation('App\Models\User', 'created', false); // Disable
$manager->toggleObservation('App\Models\User', 'created', true);  // Enable
```

### Conditional Observation

[](#conditional-observation)

```
use Fereydooni\LaravelObservable\Attributes\Observe;

#[Observe(
    target: 'App\Models\User',
    event: 'created',
    callback: 'App\Services\AdminLogger@log',
    condition: 'isAdmin'
)]
class AdminUserObserver
{
    public function isAdmin($model)
    {
        return $model->role === 'admin';
    }

    public function handle($model)
    {
        // This will only trigger for admin users
    }
}
```

Configuration
-------------

[](#configuration)

The package comes with a configuration file that allows you to:

- Enable/disable observation globally
- Set default priority for observations
- Configure logging backend (database or file)
- Enable/disable conditional observation

Testing
-------

[](#testing)

```
composer test
```

License
-------

[](#license)

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

###  Health Score

14

—

LowBetter than 1% of packages

Maintenance34

Infrequent updates — may be unmaintained

Popularity0

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity15

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/101217538?v=4)[Behnam Fereydooni](/maintainers/Behnamfe76)[@Behnamfe76](https://github.com/Behnamfe76)

---

Top Contributors

[![Behnamfe76](https://avatars.githubusercontent.com/u/101217538?v=4)](https://github.com/Behnamfe76 "Behnamfe76 (2 commits)")

### Embed Badge

![Health badge](/badges/fereydooni-laravel-observable/health.svg)

```
[![Health](https://phpackages.com/badges/fereydooni-laravel-observable/health.svg)](https://phpackages.com/packages/fereydooni-laravel-observable)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
