You can create instances of pages from classes and register them in the admin panel.
# Make
To create a page instance, use the static make()
method:
make( ?string $title = null, ?string $alias = null, ?ResourceContract $resource = null)
title
- page title;alias
- alias for page url;resource
- the resource to which the page belongs.
use App\MoonShine\Pages\CustomPage; //... CustomPage::make('Custom page', 'custom_page') //...
# Declaring pages in the system
To register the page in the system and immediately add a its link in the navigation menu
use the service provider MoonShineServiceProvider
:
namespace App\Providers; use App\MoonShine\Pages\CustomPage; use MoonShine\Providers\MoonShineApplicationServiceProvider; class MoonShineServiceProvider extends MoonShineApplicationServiceProvider{ //... protected function menu(): array { return [ MenuItem::make('Custom page', CustomPage::make('Custom page', 'custom_page')) ]; } //...}
You can learn about advanced settings in the section
Menu
.
If you only need to register the page in the system without adding it to the navigation menu,
then you need to use the pages()
method:
namespace App\Providers; use App\MoonShine\Pages\CustomPage; use MoonShine\Providers\MoonShineApplicationServiceProvider; class MoonShineServiceProvider extends MoonShineApplicationServiceProvider{ public function pages(): array { return [ CustomPage::make('Title page', 'custom_page') ]; } //...}
# Title/Subtitle
The setTitle()
method allows you to change the page title,
and the setSubTitle()
method consequently the subtitle.
setTitle(string $title)
setSubTitle(string $subtitle)
use App\MoonShine\Pages\CustomPage; //... public function pages(): array{ return [ CustomPage::make('Title page', 'custom_page') ->setTitle('New title') ->setSubTitle('Subtitle') ];} //...
# Layout
The setLayout()
method allows you to change the Layout template of a page instance.
setLayout(string $layout)
use App\MoonShine\Pages\CustomPage; //... public function pages(): array{ return [ CustomPage::make('Title page', 'custom_page') ->setLayout('custom_layouts.app') ];} //...
# Breadcrumbs
The setBreadcrumbs()
method allows you to change the breadcrumbs of a page.
use App\MoonShine\Pages\CustomPage; //... public function pages(): array{ return [ CustomPage::make('Title page', 'custom_page') ->setBreadcrumbs([ '#' => $this->title() ]) ];} //...
# Alias
The alias()
method allows you to change the alias for a page instance.
alias(string $alias)
use App\MoonShine\Pages\CustomPage; //... public function pages(): array{ return [ CustomPage::make('Title page') ->alias('custom-page') ];} //...
# Quick page
If you need to add a page without creating a class, but simply specifying a blade view, we recommend using ViewPage
MenuItem::make( 'Custom', ViewPage::make() ->setTitle('Hello') ->setLayout('custom_layout') ->setContentView('my-form', ['param' => 'value'])),
# Render
You can display the quick page outside of MoonShine by simply returning it to the Controller
class HomeController extends Controller{ public function __invoke(Request $request): Page { $articles = Article::query() ->published() ->latest() ->take(6) ->get(); return ViewPage::make() ->setTitle('Welcome') ->setLayout('layouts.app') ->setContentView('welcome', ['articles' => $articles]); }}