Blocks

Attach ordered PublishBlock content to a page using block templates.

Blocks

A PublishBlock belongs to a single page (publish_page_id) and renders one piece of content — a hero, a feature grid, a quote, a carousel, and so on. Blocks are a flat, ordered list per page (ordered by sort); they are not recursive.

Creating blocks

php
use OiLab\OiLaravelPublish\Models\PublishBlock;

$hero = PublishBlock::create([
    'publish_page_id' => $page->id,
    'template_key'    => 'hero',
    'name'            => 'Hero',
    'key'             => 'hero',
    'props'           => ['heading' => 'Welcome', 'alignment' => 'center'],
    'sort'            => 0,
]);

props resolves to the typed class declared by the block's template — here a HeroData. See Typed props.

Keys and ordering

key is a per-page identifier (e.g. an in-page anchor) and is unique per page — the same key may be reused on another page. Blocks read back ordered by sort:

php
$page->blocks;            // ordered by `sort`
$block->page;             // parent PublishPage
$block->template();       // PublishTemplateData

Fields

FieldTypeNotes
namestringrequired
keystringunique per publish_page_id
excerptstring?short summary
descriptiontext?rendered with the block renderer
propsjsontyped via PropsCast
template_keystringreferences a block template
publish_page_idintowning page
sortintordering within the page
is_activebooldefaults to true

Deleting a page cascades to its blocks. Blocks are soft-deletable and carry the same audit/uuid columns as pages.

Project under MIT License.
Design by