PHPackages                             waad/laravel-dynamic-observer - 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. waad/laravel-dynamic-observer

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

waad/laravel-dynamic-observer
=============================

Call observer of the model without requiring in any provider, support multi observers

v2.0.0(1mo ago)5139↓50%MITPHPPHP ^8.0CI passing

Since Jun 5Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/waadmawlood/laravel-dynamic-observer)[ Packagist](https://packagist.org/packages/waad/laravel-dynamic-observer)[ RSS](/packages/waad-laravel-dynamic-observer/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (4)Dependencies (5)Versions (9)Used By (0)

Laravel Dynamic Observer
========================

[](#laravel-dynamic-observer)

> Register model observers dynamically without service providers. Supports single and multiple observers.

Automatically connect your Laravel models to observers using traits or attributes — no service provider required.

---

Features
--------

[](#features)

- Automatic observer registration via trait
- Custom observer support with `$observer` property
- Multiple observers support
- PHP 8.0+ attribute-based configuration
- Zero configuration needed for convention-based observers

---

Requirements
------------

[](#requirements)

- PHP 8.0+
- Laravel 8.0+

---

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

[](#installation)

```
composer require waad/laravel-dynamic-observer
```

---

Quick Start
-----------

[](#quick-start)

Add the `HasObserver` trait to your model:

```
use Illuminate\Database\Eloquent\Model;
use Waad\Observer\HasObserver;

class Post extends Model
{
    use HasObserver;
}
```

The observer will beauto-detected based on naming convention (`PostObserver` in `App\Observers`).

---

Usage
-----

[](#usage)

### 1. Automatic Observer (Convention-Based)

[](#1-automatic-observer-convention-based)

The observer is automatically detected by naming convention:

```
// App\Models\Post → App\Observers\PostObserver
use Waad\Observer\HasObserver;

class Post extends Model
{
    use HasObserver;
}
```

### 2. Custom Observer

[](#2-custom-observer)

Specify a custom observer class:

```
use App\Observers\CustomObserver;
use Waad\Observer\HasObserver;

class Post extends Model
{
    use HasObserver;

    public static $observer = CustomObserver::class;
}
```

### 3. Multiple Observers

[](#3-multiple-observers)

Register multiple observers:

```
use App\Observers\FirstObserver;
use App\Observers\SecondObserver;
use Waad\Observer\HasObserver;

class Post extends Model
{
    use HasObserver;

    public static $observer = [FirstObserver::class, SecondObserver::class];
}
```

### 4. Using Attributes (PHP 8.0+)

[](#4-using-attributes-php-80)

Use the `#[HasObservers]` attribute:

```
use App\Observers\CustomObserver;
use Waad\Observer\Attributes\HasObservers;
use Waad\Observer\HasObserver;

#[HasObservers(CustomObserver::class)]
class Post extends Model
{
    use HasObserver;
}
```

> **Note:** When using the attribute, you must also use the trait `HasObserver`.

---

Creating Observers
------------------

[](#creating-observers)

Generate an observer with Artisan:

```
php artisan make:observer PostObserver --model=Post
```

### Observer Methods

[](#observer-methods)

```
namespace App\Observers;

use App\Models\Post;

class PostObserver
{
    public function creating(Post $post)
    {
        // Called before creating
    }

    public function created(Post $post)
    {
        // Called after creating
    }

    public function updating(Post $post)
    {
        // Called before updating
    }

    public function updated(Post $post)
    {
        // Called after updating
    }

    public function saving(Post $post)
    {
        // Called before saving (create or update)
    }

    public function saved(Post $post)
    {
        // Called after saving
    }

    public function deleting(Post $post)
    {
        // Called before deleting
    }

    public function deleted(Post $post)
    {
        // Called after deleting
    }

    public function restoring(Post $post)
    {
        // Called before restoring (soft deletes)
    }

    public function restored(Post $post)
    {
        // Called after restoring
    }

    public function retrieved(Post $post)
    {
        // Called after retrieving
    }
}
```

---

Testing
-------

[](#testing)

```
composer test
```

---

License
-------

[](#license)

MIT License. See [LICENSE](LICENSE) for details.

###  Health Score

45

—

FairBetter than 92% of packages

Maintenance91

Actively maintained with recent releases

Popularity15

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

 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.

###  Release Activity

Cadence

Every ~207 days

Recently: every ~111 days

Total

6

Last Release

41d ago

Major Versions

v1.1.1 → 2.x-dev2026-04-04

PHP version history (3 changes)v1.0.0PHP &gt;=7.4

v1.1.0PHP &gt;=7.3

2.x-devPHP ^8.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/44348636?v=4)[Waad Mawlood](/maintainers/waadmawlood)[@waadmawlood](https://github.com/waadmawlood)

---

Top Contributors

[![waadmawlood](https://avatars.githubusercontent.com/u/44348636?v=4)](https://github.com/waadmawlood "waadmawlood (25 commits)")

---

Tags

laravelmodelobservermodel observerlaravel-observer

###  Code Quality

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/waad-laravel-dynamic-observer/health.svg)

```
[![Health](https://phpackages.com/badges/waad-laravel-dynamic-observer/health.svg)](https://phpackages.com/packages/waad-laravel-dynamic-observer)
```

###  Alternatives

[gbrock/laravel-table

Table functionality for Laravel models

7644.3k](/packages/gbrock-laravel-table)[mckenziearts/laravel-command

A simple Laravel package to provide artisan new commands

321.2k](/packages/mckenziearts-laravel-command)

PHPackages © 2026

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