Artisan command for creating observer classes in Laravel.
Tested on Laravel versions: 5.3, 5.4, 5.5, 5.6.
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,
To add observer class you need to enter name, relative model's namespace and methods(optional). 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 'App\Models\User' --methods=created,updated
There are 6 methods: creating, created, updating, updated, deleting, deleted.
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
}
(Only for Laravel 5.4 and below) Remove service provider from app.php.
Remove by composer.
$ composer remove nicksynev/make-observer-command