Skip to content

Pages ​

A Page is a screen with a form but no Eloquent model behind it: a settings page, the user's profile... For anything else, see Custom pages.

A Page reuses exactly the same Fields system as a Resource, but reads and saves the data however you like, there is no required Model:

php
final class SiteSettingsPage extends Page
{
    public function fields(): array
    {
        return [
            Section::make('Site Settings')
                ->schema([
                    Text::make('site_name')->rules('required', 'string', 'max:255'),
                    Toggle::make('maintenance_mode')->default(false),
                ]),
        ];
    }

    public function data(): array
    {
        return Cache::get('site_settings', [
            'site_name' => 'Arrel Workbench',
            'maintenance_mode' => false,
        ]);
    }

    public function save(array $data): void
    {
        Cache::forever('site_settings', $data);
    }
}

The three abstract methods:

MethodDescription
fields(): array<Section>Same as on a Resource.
data(): arrayThe initial values of the form. Where they come from is up to you: cache, a configuration file, a table of your own without Eloquent...
save(array $data): voidCalled with the data already validated against the fields' rules().

As with a Resource, slug() is deduced from the class name (SiteSettingsPage → site-settings) and can be overridden with protected static ?string $slug. canView(): bool (true by default) controls its visibility.

Once registered on the Panel via ->pages([SiteSettingsPage::class]), it appears in the navigation with no additional step.

Profile page ​

A Page can be designated as the user's profile page, and the panel dedicates a link to it in the sidebar:

php
final class AccountPage extends Page
{
    public function fields(): array
    {
        return [
            Section::make()->schema([
                Text::make('name')->rules('required', 'string', 'max:255'),
            ]),
        ];
    }

    public function data(): array
    {
        return ['name' => (string) auth()->user()?->name];
    }

    public function save(array $data): void
    {
        auth()->user()?->forceFill(['name' => $data['name']])->save();
    }
}
php
Panel::make('admin')->profile(AccountPage::class);

The link is only shown to users for whom canView() is true. To decide where the user lands when entering the panel, see home().

Like a Resource, a Page can be placed in the navigation with icon(), navigationGroup() and navigationSort(), all three optional and returning null by default. label() is the text of the link.