thomascombe / laravel-observer-attributes
Use PHP 8 attributes to register eloquent model observers in a Laravel app
0.1
2021-04-23 19:05 UTC
Requires
- php: ^8.0
- illuminate/contracts: ^8.0
- spatie/laravel-package-tools: ^1.4.3
Requires (Dev)
- nunomaduro/collision: ^5.3
- orchestra/testbench: ^6.0
- phpunit/phpunit: ^9.3
- vimeo/psalm: ^4.4
This package is auto-updated.
Last update: 2024-10-24 03:20:06 UTC
README
Use PHP 8 attributes to register eloquent model observers in a Laravel app
Installation
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'), ], ];
Usage
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 { }
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.