Your first content type
Declare a type as a PHP class, register it, give it a table and a view, and write its first entry.
A content type is a class extending Entry. Its typed properties, each with a field attribute, are its fields: one declaration gives a field its column, its form field in the admin, its validation rules, its JSON Schema and its PHP type. In development mainstay:sync builds the table; in production a migration you write does.
Declare it
namespace App\Content;
use Carbon\CarbonImmutable;
use Mainstay\Content\Entry;
use Mainstay\Content\Route;
use Mainstay\Fields\Date;
use Mainstay\Fields\Text;
use Mainstay\Fields\Textarea;
#[Route('/blog/{slug}')]
class Article extends Entry
{
#[Text(required: true, localized: true)]
public string $slug;
#[Textarea(localized: true)]
public ?string $summary;
#[Date(required: true)]
public CarbonImmutable $publishedOn;
}
Every entry already has a title and content without declaring them. #[Route] gives it a path built from its fields, so this one is served at /blog/ and its slug.
Register it
Types are registered, not discovered. Name them in a service provider's boot():
use App\Content\Article;
use Mainstay\Facades\Mainstay;
Mainstay::types([Article::class]);
Give it a table
php artisan mainstay:sync
The type gets a table named after its handle, article, with a column per field, and article_locales beside it for the fields that are translated. Sync asks before it drops a column or retypes one in a way that changes what is stored; a renamed property reads as a dropped column and a new one.
Give it a view
An entry renders with the Blade view named after its type's handle, and gets itself as $entry:
<article>
<h1>{{ $entry->title }}</h1>
<p>{{ $entry->publishedOn->isoFormat('D MMMM YYYY') }}</p>
<div class="prose">{{ $entry->content }}</div>
</article>
Write an entry
Write one in the admin, which now lists Articles, or from code. A seeder, a command or tinker has nobody signed in, so it says it writes on its own authority:
Mainstay::create(Article::class, [
'title' => 'Hello',
'slug' => 'hello',
'publishedOn' => '2026-11-03',
], overrideAccess: true);
Visit /blog/hello. The same call from the admin, a seeder or the API is validated by the same rules, so none of them can save what another would refuse. Permissions apply to all of them too, except where code passes overrideAccess: true, as this one does.