/** * Raise an event when a post is deleted. * * @return void */ public static function boot() { parent::boot(); static::deleted(function ($user) { $user->raise(new UserWasDeleted($user)); }); }
/** * Raise an event when a discussion is deleted. * * @return void */ public static function boot() { parent::boot(); static::deleted(function ($discussion) { $discussion->raise(new DiscussionWasDeleted($discussion)); $discussion->posts()->allTypes()->delete(); $discussion->readers()->detach(); }); }
/** * Raise an event when a post is deleted. Add an event listener to set the * post's number, and update the discussion's number index, when inserting * a post. * * @return void */ public static function boot() { parent::boot(); static::creating(function ($post) { $post->type = $post::$type; $post->number = ++$post->discussion->number_index; $post->discussion->save(); }); static::deleted(function ($post) { $post->raise(new PostWasDeleted($post)); }); static::addGlobalScope(new RegisteredTypesScope()); }