Globals
Settings with one value per site, such as a menu and a footer, read from any view.
A global is a type with one row per site and no route: the menu, the footer line, a contact address. It is a class extending GlobalSet, so named because Global is a reserved word in PHP.
Declare one
class Layout extends GlobalSet
{
#[Relation(to: Page::class, localized: true)]
public array $menu;
#[Textarea(localized: true)]
public ?string $tagline;
#[Text(localized: true)]
public ?string $copyright;
}
Its fields are a type's fields: a relation, an image or a select works here as it does on an entry. Register it with your other types and sync.
Read it
$layout = Mainstay::global(Layout::class);
It is this site's one, in the locale read, or null where it has not been written in that locale: absent, as an untranslated entry is, rather than defaults nobody stored. A layout component reads it once and draws the header and footer from it.
Write it
Mainstay::saveGlobal(Layout::class, [
'tagline' => 'A CMS that lives in your Laravel application.',
], overrideAccess: true);
In the admin, a global is a form of its own with Save draft and Publish and a history, as an entry has. Its capabilities are named after it, edit_layout and publish_layout, and edit_globals and publish_globals cover every global.
A global holds fields, not blocks. A navigation or a footer built from blocks is a template part, which Mainstay does not have yet.
Template parts are planned; the roadmap says when.