Laravel Eloquent Events Implementation -
i updating model instance or inserting new 1 this:
$model = model::updateorcreate([id' => $request['id']], $model_to_update_array); i want execute code when existing model instance ('tourist') updated (and not when new 1 created or nothing changes).
i've read https://laravel.com/docs/5.4/eloquent#events eloquent events , seems me need use updated or updating event. understand these events 'built-in' in laravel, don't have use lot of stuff here: https://laravel.com/docs/5.4/events
i haven't found tutorial showing how implement eloquent events. since new events conception @ all, it's hard me understand how use them. can drop link tutorial eloquent events (not events in general, eloqeunt events in particular) or maybe can shortly explained here?
thank in advance!
the easiest way add eloquent event particular model overwrite boot() method:
protected static function boot() { parent::boot(); static::updating(function ($model) { }); } when put in model anonymous function run every time when model being updated. please note there difference between calling static::updating() , static::updated() depending on when want execute code.
Comments
Post a Comment