nicksynev/make-observer-command

Artisan command for creating Observer classes in Laravel
15,754 9
Install
composer require nicksynev/make-observer-command
Latest Version:v0.0.4
License:MIT
Last Updated:May 30, 2018
Links: GitHub  ·  Packagist
Maintainer: NickSynev

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

Related Packages

larapack/command-verification

Makes Artisan Commands prompt the console if it should continue.

15 1
larapack/command-validation

Enable a method for Artisan Commands to validate the output of methods like `ask...

4,261 12
hariadi/laravel-boilerplate-generator

Generate Model, attribute, relation, scope trait and repository for Laravel Boil...

609 9
abhijitghogre/laravel-db-clear-command

Laravel artisan command to drop all database tables and rerun the migrations.

3,527 5
jrenton/laravel-5-scaffold

Fastest way to rapidly scaffold a laravel application

268 4