# Content from a database Error

**URL:** <https://forum.getkirby.com/t/content-from-a-database-error/30821>\
**Category:** Questions\
**Tags:** v4\
**Created:** [February 18, 2024, 12:56am UTC](https://forum.getkirby.com/t/content-from-a-database-error/30821 "2024-02-18T00:56:26Z")\
**Posts on this page:** 1\
**Showing post:** 7

<div class="post-metadata">

**Author:** ![selig](https://avatars.discourse-cdn.com/v4/letter/s/57b2e6/32.png) [@selig](https://forum.getkirby.com/u/selig)\
**Post date:** [February 18, 2024, 3:58pm UTC](https://forum.getkirby.com/t/content-from-a-database-error/30821/7 "2024-02-18T15:58:04Z")

</div>

I also realised that when I change the status of a page in the panel from listed to unlisted, the database value changes to null, but the pages remain visible in the frontend.

This is the code of my model file comment.php (as copied from the Documentation)

```auto
<?php

class CommentPage extends Kirby\Cms\Page
{
    public function changeSlug(string $slug, string|null $languageCode = null): static
    {
        // always sanitize the slug
        $slug = Str::slug($slug);

        $data['slug'] = $slug;

        if ($comment = Db::first('comments', '*', ['slug' => $this->slug()])) {
            Db::update('comments', $data, ['slug' => $this->slug()]);
        }

        return $this;
    }

    protected function changeStatusToDraft(): static
    {
        $data['status'] = 'null';

        if ($comment = Db::first('comments', '*', ['slug' => $this->slug()])) {
            Db::update('comments', $data, ['slug' => $this->slug()]);
        }

        return $this;
    }

    protected function changeStatusToListed(int|null $position = null): static
    {
        // create a sorting number for the page
        $num = $this->createNum($position);

        // don't sort if not necessary
        if ($this->status() === 'listed' && $num === $this->num()) {
            return $this;
        }

        $data['status'] = 'listed';

        if ($comment = Db::first('comments', '*', ['slug' => $this->slug()])) {
            Db::update('comments', $data, ['slug' => $this->slug()]);
        }

        if ($this->blueprint()->num() === 'default') {
            $this->resortSiblingsAfterListing($num);
        }

        return $this;
    }

    protected function changeStatusToUnlisted(): static
    {
        if ($this->status() === 'unlisted') {
            return $this;
        }

        $data['status'] = 'unlisted';

        if ($comment = Db::first('comments', '*', ['slug' => $this->slug()])) {
            Db::update('comments', $data, ['slug' => $this->slug()]);
        }

        $this->resortSiblingsAfterUnlisting();

        return $this;
    }

    public function changeTitle(string $title, string|null $languageCode = null): static
    {
        $data['title'] = $title;

        if ($comment = Db::first('comments', '*', ['slug' => $this->slug()])) {
            Db::update('comments', $data, ['slug' => $this->slug()]);
        }

        return $this;
    }

    public function delete(bool $force = false): bool
    {
        return Db::delete('comments', ['slug' => $this->slug()]);
    }

    public function isDraft(): bool
    {
        return in_array($this->content()->status(), ['listed', 'unlisted']) === false;
    }

    public function writeContent(array $data, string|null $languageCode = null): bool
    {
        unset($data['title']);

        if ($comment = Db::first('comments', '*', ['slug' => $this->slug()])) {
            return Db::update('comments', $data, ['slug' => $this->slug()]);
        } else {
            $data['slug'] = $this->slug();
            return Db::insert('comments', $data);
        }
    }
}

```

---

_[View the full topic](https://forum.getkirby.com/t/content-from-a-database-error/30821)._
