Skip to content

Hierarchy Logic

Pyxis CMS uses a Tree Structure to organize content. Each page can have an optional “parent,” which directly influences the URL structure and site navigation.

In the database, the hierarchy is based on the parent_id column, which points to the id of another page within the same table.

  • Root Page: parent_id is NULL. The URL is simply /{slug}.
  • Child Page: parent_id points to a parent. The URL is /{parent_slug}/{child_slug}.

The full path of a page is not hardcoded in a single column. Instead, it is computed dynamically by the Eloquent model (Laravel) during every API request.

The model traverses up the tree until it hits a page without a parent (Root), concatenating the slugs into a single path.

// Logical example in the Page model:
protected function fullUrl(): Attribute
{
return Attribute::make(
get: function() {
// If page have parent, get his full url
if ($this->parent_id && $this->parent) {
return rtrim($this->parent->full_url, '/') . '/' . $this->slug;
}
// If page is main return /
return '/' . $this->slug;
},
);
}
  1. No Redundancy: Changing a parent's slug automatically "moves" all its children to the new URL from the API's perspective.
  2. Breadcrumbs: This structure allows the API to easily return an array of ancestors for any given page, enabling Next.js to render breadcrumb navigation.
  3. Integrity: The API validation system (see Slug Resolution) ensures that a subpage is never rendered if the user skips any segment of the parent path.

A dedicated /api/navigation endpoint is planned. It will return the entire page tree (titles and URLs only) to automatically build navigation menus in Next.js.