Flarum\Core\Discussion::boot PHP Method

boot() public static method

Boot the model.
public static boot ( ) : void
return void
    public static function boot()
    {
        parent::boot();
        static::deleted(function ($discussion) {
            $discussion->raise(new DiscussionWasDeleted($discussion));
            // Delete all of the posts in the discussion. Before we delete them
            // in a big batch query, we will loop through them and raise a
            // PostWasDeleted event for each post.
            $posts = $discussion->posts()->allTypes();
            foreach ($posts->get() as $post) {
                $discussion->raise(new PostWasDeleted($post));
            }
            $posts->delete();
            // Delete all of the 'state' records for all of the users who have
            // read the discussion.
            $discussion->readers()->detach();
        });
    }