nicksynev/make-observer-command

Artisan command for creating Observer classes in Laravel

Installs: 13 946

Dependents: 0

Suggesters: 0

Security: 0

Stars: 9

Watchers: 2

Forks: 3

Type:laravel-artisan-command

v0.0.4 2018-05-30 18:33 UTC

This package is not auto-updated.

Last update: 2024-05-12 02:15:31 UTC


README

Total Downloads Latest Stable Version License

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