Pages

Create recursive PublishPage models with parent/children, slugs and ordering.

Pages

A PublishPage is a recursive content page. Pages form a tree through parent_id, expose children ordered by sort, reference a page template by template_key, and carry typed props.

Creating pages

php
use OiLab\OiLaravelPublish\Models\PublishPage;

$home = PublishPage::create([
    'template_key' => 'landing',
    'name'         => 'Home',
    'slug'         => 'home',
]);

$about = PublishPage::create([
    'parent_id'    => $home->id,
    'template_key' => 'default',
    'name'         => 'About',
    'slug'         => 'about',
]);

The page tree

php
$home->children;   // Collection<PublishPage>, ordered by `sort`
$about->parent;    // PublishPage
$home->blocks;     // Collection<PublishBlock>, ordered by `sort`

Slugs

Slugs are unique per parent, not globally — two pages under different parents may share a slug, which suits path-based routing. A duplicate slug under the same parent throws a QueryException.

Fields

FieldTypeNotes
namestringrequired
slugstringunique per parent_id
excerptstring?short summary
descriptiontext?rendered with the page renderer
propsjsontyped via PropsCast
template_keystringreferences a page template
parent_idint?self-reference (recursive)
sortintsibling ordering
is_activebooldefaults to true

Pages are soft-deletable, carry created_by / updated_by audit columns, and a generated uuid.

Project under MIT License.
Design by