You can create instances of pages from classes and register them in the admin panel.
To create a page instance, use the static make()
method:
make(
?string $title = null,
?string $alias = null,
?ResourceContract $resource = null
)
make(
?string $title = null,
?string $alias = null,
?ResourceContract $resource = null
)
make(
?string $title = null,
?string $alias = null,
?ResourceContract $resource = null
)
make(
?string $title = null,
?string $alias = null,
?ResourceContract $resource = null
)
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')
use App\MoonShine\Pages\CustomPage;
//...
CustomPage::make('Custom page', 'custom_page')
//...
use App\MoonShine\Pages\CustomPage;
//...
CustomPage::make('Custom page', 'custom_page')
//...
use App\MoonShine\Pages\CustomPage;
//...
CustomPage::make('Custom page', 'custom_page')
//...
use App\MoonShine\Pages\CustomPage;
//...
CustomPage::make('Custom page', 'custom_page')
//...
To register the page in the system and immediately add 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'))
];
}
}
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'))
];
}
//...
}
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'))
];
}
//...
}
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'))
];
}
//...
}
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')
];
}
}
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')
];
}
//...
}
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')
];
}
//...
}
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')
];
}
//...
}
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')
];
}
//...
}
The setTitle()
method allows you to change the page title, and the setSubTitle()
method consequently the subtitle.
setTitle(string $title)
setTitle(string $title)
setTitle(string $title)
setTitle(string $title)
setTitle(string $title)
setSubTitle(string $subtitle)
setSubTitle(string $subtitle)
setSubTitle(string $subtitle)
setSubTitle(string $subtitle)
setSubTitle(string $subtitle)
use App\MoonShine\Pages\CustomPage;
public function pages(): array
{
return [
CustomPage::make('Title page', 'custom_page')
->setTitle('New title')
->setSubTitle('Subtitle')
];
}
use App\MoonShine\Pages\CustomPage;
//...
public function pages(): array
{
return [
CustomPage::make('Title page', 'custom_page')
->setTitle('New title')
->setSubTitle('Subtitle')
];
}
//...
use App\MoonShine\Pages\CustomPage;
//...
public function pages(): array
{
return [
CustomPage::make('Title page', 'custom_page')
->setTitle('New title')
->setSubTitle('Subtitle')
];
}
//...
use App\MoonShine\Pages\CustomPage;
//...
public function pages(): array
{
return [
CustomPage::make('Title page', 'custom_page')
->setTitle('New title')
->setSubTitle('Subtitle')
];
}
//...
use App\MoonShine\Pages\CustomPage;
//...
public function pages(): array
{
return [
CustomPage::make('Title page', 'custom_page')
->setTitle('New title')
->setSubTitle('Subtitle')
];
}
//...
The setLayout()
method allows you to change the Layout template of a page instance.
setLayout(string $layout)
setLayout(string $layout)
setLayout(string $layout)
setLayout(string $layout)
setLayout(string $layout)
use App\MoonShine\Pages\CustomPage;
public function pages(): array
{
return [
CustomPage::make('Title page', 'custom_page')
->setLayout('custom_layouts.app')
];
}
]
use App\MoonShine\Pages\CustomPage;
//...
public function pages(): array
{
return [
CustomPage::make('Title page', 'custom_page')
->setLayout('custom_layouts.app')
];
}
//...
]
use App\MoonShine\Pages\CustomPage;
//...
public function pages(): array
{
return [
CustomPage::make('Title page', 'custom_page')
->setLayout('custom_layouts.app')
];
}
//...
]
use App\MoonShine\Pages\CustomPage;
//...
public function pages(): array
{
return [
CustomPage::make('Title page', 'custom_page')
->setLayout('custom_layouts.app')
];
}
//...
]
use App\MoonShine\Pages\CustomPage;
//...
public function pages(): array
{
return [
CustomPage::make('Title page', 'custom_page')
->setLayout('custom_layouts.app')
];
}
//...
]
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()
])
];
}
use App\MoonShine\Pages\CustomPage;
//...
public function pages(): array
{
return [
CustomPage::make('Title page', 'custom_page')
->setBreadcrumbs([
'#' => $this->title()
])
];
}
//...
use App\MoonShine\Pages\CustomPage;
//...
public function pages(): array
{
return [
CustomPage::make('Title page', 'custom_page')
->setBreadcrumbs([
'#' => $this->title()
])
];
}
//...
use App\MoonShine\Pages\CustomPage;
//...
public function pages(): array
{
return [
CustomPage::make('Title page', 'custom_page')
->setBreadcrumbs([
'#' => $this->title()
])
];
}
//...
use App\MoonShine\Pages\CustomPage;
//...
public function pages(): array
{
return [
CustomPage::make('Title page', 'custom_page')
->setBreadcrumbs([
'#' => $this->title()
])
];
}
//...
The alias()
method allows you to change the alias for a page instance.
alias(string $alias)
alias(string $alias)
alias(string $alias)
alias(string $alias)
alias(string $alias)
use App\MoonShine\Pages\CustomPage;
public function pages(): array
{
return [
CustomPage::make('Title page')
->alias('custom-page')
];
}
use App\MoonShine\Pages\CustomPage;
//...
public function pages(): array
{
return [
CustomPage::make('Title page')
->alias('custom-page')
];
}
//...
use App\MoonShine\Pages\CustomPage;
//...
public function pages(): array
{
return [
CustomPage::make('Title page')
->alias('custom-page')
];
}
//...
use App\MoonShine\Pages\CustomPage;
//...
public function pages(): array
{
return [
CustomPage::make('Title page')
->alias('custom-page')
];
}
//...
use App\MoonShine\Pages\CustomPage;
//...
public function pages(): array
{
return [
CustomPage::make('Title page')
->alias('custom-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'])
),
MenuItem::make(
'Custom',
ViewPage::make()
->setTitle('Hello')
->setLayout('custom_layout')
->setContentView('my-form', ['param' => 'value'])
),
MenuItem::make(
'Custom',
ViewPage::make()
->setTitle('Hello')
->setLayout('custom_layout')
->setContentView('my-form', ['param' => 'value'])
),
MenuItem::make(
'Custom',
ViewPage::make()
->setTitle('Hello')
->setLayout('custom_layout')
->setContentView('my-form', ['param' => 'value'])
),
MenuItem::make(
'Custom',
ViewPage::make()
->setTitle('Hello')
->setLayout('custom_layout')
->setContentView('my-form', ['param' => 'value'])
),
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]);
}
}
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]);
}
}
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]);
}
}
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]);
}
}
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]);
}
}