Yes, that's right, EventServiceProvider is the best place for it.
However, you can create Observers to be clean. I will give you a quick example.
EventServiceProvider
<?php namespace App\Providers; use Illuminate\Contracts\Events\Dispatcher as DispatcherContract; use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider; use App\Models\Users; use App\Observers\UserObserver; class EventServiceProvider extends ServiceProvider { public function boot(DispatcherContract $events) { parent::boot($events); Users::observe(new UserObserver()); } }
UserObserver
<?php namespace App\Observers; class UserObserver { public function updated($model) { } }
Observer will be the place where the saved , updated , created , etc. functions will be executed.
Additional Observer Information: http://laravel.com/docs/5.0/eloquent#model-observers
Szenis
source share