Use PHP 8 attributes to register eloquent model observers in a Laravel app
thomascombe/laravel-observer-attributes is a Laravel package for use php 8 attributes to register eloquent model observers in a laravel app.
It currently has 2 GitHub stars and 4 downloads on Packagist (latest version 0.1).
Install it with composer require thomascombe/laravel-observer-attributes.
Discover more Laravel packages by thomascombe
or browse all Laravel packages to compare alternatives.
Last updated

You can install the package via composer:
composer require thomascombe/laravel-observer-attributes
You can publish the config file with:
php artisan vendor:publish --provider="Thomascombe\ObserverAttributes\ObserverAttributesServiceProvider" --tag="laravel-observer-attributes-config"
This is the contents of the published config file:
return [
'directories' => [
app_path('Models'),
],
];
Add single observer to model:
use App\Observers\UserObserver;
#[Observer(UserObserver::class)]
class User extends Authenticatable
{
}
It's just like:
User::observe(UserObserver::class);
in EventServiceProvider
Add multiples observers to model:
use App\Observers\EntityObserver;
use App\Observers\UserObserver;
#[Observer(UserObserver::class, EntityObserver::class)]
class User extends Authenticatable
{
}
composer test
Please see CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING for details.
Please review our security policy on how to report security vulnerabilities.
The MIT License (MIT). Please see License File for more information.