Flarum\Core\User::boot PHP Method

boot() public static method

Boot the model.
public static boot ( ) : void
return void
    public static function boot()
    {
        parent::boot();
        // Don't allow the root admin to be deleted.
        static::deleting(function (User $user) {
            if ($user->id == 1) {
                throw new DomainException('Cannot delete the root admin');
            }
        });
        static::deleted(function (User $user) {
            $user->raise(new UserWasDeleted($user));
            // Delete all of the posts by the user. Before we delete them
            // in a big batch query, we will loop through them and raise a
            // PostWasDeleted event for each post.
            $posts = $user->posts()->allTypes();
            foreach ($posts->get() as $post) {
                $user->raise(new PostWasDeleted($post));
            }
            $posts->delete();
            $user->read()->detach();
            $user->groups()->detach();
            $user->accessTokens()->delete();
            $user->notifications()->delete();
        });
        static::$dispatcher->fire(new ConfigureUserPreferences());
    }