nicksynev / make-observer-command
Artisan command for creating Observer classes in Laravel
Installs: 14 586
Dependents: 0
Suggesters: 0
Security: 0
Stars: 9
Watchers: 1
Forks: 3
Type:laravel-artisan-command
Requires
This package is not auto-updated.
Last update: 2025-03-16 07:04:26 UTC
README
make-observer-command
Artisan command for creating observer classes in Laravel.
Tested on Laravel versions: 5.3, 5.4, 5.5, 5.6.
Installation
Install package via composer.
$ composer require nicksynev/make-observer-command
(Only for Laravel 5.4 and below) Add service provider into your app.php file in config folder.
NickSynev\MakeObserverCommand\MakeObserverCommandServiceProvider::class,
Usage
To add observer you need to enter class name. It will create Observers folder (if you dont have one) in your app directory and put class there. Also supports subfolder structure (for example User/UserObserver).
$ php artisan make:observer UserObserver
Additionally you can specify related model's namespace and methods.
$ php artisan make:observer UserObserver --model='App\Models\User' --methods=created,updated
There are 10 methods: creating, created, updating, updated, saving, saved, deleting, deleted, restoring, restored.
If no method chosen puts all of them to a class.
Do not forget to init your observer for example in AppServiceProvider boot method.
public function boot() { User::observe(UserObserver::class); // Your code }
Removal
(Only for Laravel 5.4 and below) Remove service provider from app.php.
Remove by composer.
$ composer remove nicksynev/make-observer-command