Pages

You're browsing the documentation for an old version of MoonShine. Consider upgrading your project to MoonShine 2.x.

# Basics

You can create your own blank pages based on the blade view and UI components , style in your own way, as well as organize some kind of logic.

use Illuminate\Support\ServiceProvider;
use MoonShine\Menu\MenuItem;
use MoonShine\MoonShine;
use MoonShine\Resources\CustomPage;
 
class MoonShineServiceProvider extends ServiceProvider
{
public function boot(): void
{
app(MoonShine::class)->menu([
MenuItem::make(
'Page title',
CustomPage::make('Page title', 'slug', 'view', fn() => [])
)
]);
}
}

The first argument - page title.

The second argument - page slug to generate url.

The third argument - your custom blade view, which could be found in the resources/views.

The fourth argument - the data required for view.

You can use blade components which have a handler class to add your own logic.

# Without title

Sometimes it is not required to display the title on a custom page, so it can be hidden using the withoutTitle method.

use Illuminate\Support\ServiceProvider;
use MoonShine\Menu\MenuItem;
use MoonShine\MoonShine;
use MoonShine\Resources\CustomPage;
 
class MoonShineServiceProvider extends ServiceProvider
{
public function boot(): void
{
app(MoonShine::class)->menu([
MenuItem::make(
'Page title',
CustomPage::make('Page title', 'slug', 'view', fn() => [])
->withoutTitle()
)
]);
}
}

# Layout

You can use custom layout, for this you need to specify the path to it in the corresponding method.

use Illuminate\Support\ServiceProvider;
use MoonShine\Menu\MenuItem;
use MoonShine\MoonShine;
use MoonShine\Resources\CustomPage;
 
class MoonShineServiceProvider extends ServiceProvider
{
public function boot(): void
{
app(MoonShine::class)->menu([
MenuItem::make(
'Page title',
CustomPage::make('Page title', 'slug', 'view', fn() => [])
->layout('path')
)
]);
}
}
]

# class CustomPage

Pages can be created through a class, just run the command:

php artisan moonshine:page ExamplePage

As a result, a ExamplePage class will be created, which will be the basis of the custom page. It is located by default in the app/MoonShine/Pages directory.

When executing the command, you can immediately set an alias, title and blade view for your page.

php artisan moonshine:page ExamplePage --alias="example" --title="Example Page" --view="pages.example"

After creating a page, it can be added to the menu.

use Illuminate\Support\ServiceProvider;
use MoonShine\Pages\ExamplePage;
 
class MoonShineServiceProvider extends ServiceProvider
{
public function boot(): void
{
app(MoonShine::class)->menu([
MenuItem::make('Example', new ExamplePage())
]);
}
}