Вы можете создавать экземпляры страниц из классов и регистрировать их в админ-панели.
Для создания экземпляра страницы используйте статический метод make()
:
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
- заголовок страницы;
-alias
- псевдоним для URL страницы;
-resource
- ресурс, к которому принадлежит страница.
use App\MoonShine\Pages\CustomPage;
CustomPage::make('Пользовательская страница', 'custom_page')
use App\MoonShine\Pages\CustomPage;
//...
CustomPage::make('Пользовательская страница', 'custom_page')
//...
use App\MoonShine\Pages\CustomPage;
//...
CustomPage::make('Пользовательская страница', 'custom_page')
//...
use App\MoonShine\Pages\CustomPage;
//...
CustomPage::make('Пользовательская страница', 'custom_page')
//...
use App\MoonShine\Pages\CustomPage;
//...
CustomPage::make('Пользовательская страница', 'custom_page')
//...
Для регистрации страницы в системе и сразу добавления ее ссылки в навигационное меню используйте сервис-провайдер MoonShineServiceProvider
:
namespace App\Providers;
use App\MoonShine\Pages\CustomPage;
use MoonShine\Providers\MoonShineApplicationServiceProvider;
class MoonShineServiceProvider extends MoonShineApplicationServiceProvider
{
protected function menu(): array
{
return [
MenuItem::make('Пользовательская страница', CustomPage::make('Пользовательская страница', '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('Пользовательская страница', CustomPage::make('Пользовательская страница', '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('Пользовательская страница', CustomPage::make('Пользовательская страница', '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('Пользовательская страница', CustomPage::make('Пользовательская страница', '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('Пользовательская страница', CustomPage::make('Пользовательская страница', 'custom_page'))
];
}
//...
}
О расширенных настройках вы можете узнать в разделе Меню.
Если вам нужно только зарегистрировать страницу в системе без добавления ее в навигационное меню, то необходимо использовать метод pages()
:
namespace App\Providers;
use App\MoonShine\Pages\CustomPage;
use MoonShine\Providers\MoonShineApplicationServiceProvider;
class MoonShineServiceProvider extends MoonShineApplicationServiceProvider
{
public function pages(): array
{
return [
CustomPage::make('Заголовок страницы', '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('Заголовок страницы', '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('Заголовок страницы', '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('Заголовок страницы', '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('Заголовок страницы', 'custom_page')
];
}
//...
}
Метод setTitle()
позволяет изменить заголовок страницы, а метод setSubTitle()
- подзаголовок.
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('Заголовок страницы', 'custom_page')
->setTitle('Новый заголовок')
->setSubTitle('Подзаголовок')
];
}
use App\MoonShine\Pages\CustomPage;
//...
public function pages(): array
{
return [
CustomPage::make('Заголовок страницы', 'custom_page')
->setTitle('Новый заголовок')
->setSubTitle('Подзаголовок')
];
}
//...
use App\MoonShine\Pages\CustomPage;
//...
public function pages(): array
{
return [
CustomPage::make('Заголовок страницы', 'custom_page')
->setTitle('Новый заголовок')
->setSubTitle('Подзаголовок')
];
}
//...
use App\MoonShine\Pages\CustomPage;
//...
public function pages(): array
{
return [
CustomPage::make('Заголовок страницы', 'custom_page')
->setTitle('Новый заголовок')
->setSubTitle('Подзаголовок')
];
}
//...
use App\MoonShine\Pages\CustomPage;
//...
public function pages(): array
{
return [
CustomPage::make('Заголовок страницы', 'custom_page')
->setTitle('Новый заголовок')
->setSubTitle('Подзаголовок')
];
}
//...
Метод setLayout()
позволяет изменить шаблон Layout экземпляра страницы.
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('Заголовок страницы', 'custom_page')
->setLayout('custom_layouts.app')
];
}
]
use App\MoonShine\Pages\CustomPage;
//...
public function pages(): array
{
return [
CustomPage::make('Заголовок страницы', 'custom_page')
->setLayout('custom_layouts.app')
];
}
//...
]
use App\MoonShine\Pages\CustomPage;
//...
public function pages(): array
{
return [
CustomPage::make('Заголовок страницы', 'custom_page')
->setLayout('custom_layouts.app')
];
}
//...
]
use App\MoonShine\Pages\CustomPage;
//...
public function pages(): array
{
return [
CustomPage::make('Заголовок страницы', 'custom_page')
->setLayout('custom_layouts.app')
];
}
//...
]
use App\MoonShine\Pages\CustomPage;
//...
public function pages(): array
{
return [
CustomPage::make('Заголовок страницы', 'custom_page')
->setLayout('custom_layouts.app')
];
}
//...
]
Метод setBreadcrumbs()
позволяет изменить хлебные крошки страницы.
use App\MoonShine\Pages\CustomPage;
public function pages(): array
{
return [
CustomPage::make('Заголовок страницы', 'custom_page')
->setBreadcrumbs([
'#' => $this->title()
])
];
}
use App\MoonShine\Pages\CustomPage;
//...
public function pages(): array
{
return [
CustomPage::make('Заголовок страницы', 'custom_page')
->setBreadcrumbs([
'#' => $this->title()
])
];
}
//...
use App\MoonShine\Pages\CustomPage;
//...
public function pages(): array
{
return [
CustomPage::make('Заголовок страницы', 'custom_page')
->setBreadcrumbs([
'#' => $this->title()
])
];
}
//...
use App\MoonShine\Pages\CustomPage;
//...
public function pages(): array
{
return [
CustomPage::make('Заголовок страницы', 'custom_page')
->setBreadcrumbs([
'#' => $this->title()
])
];
}
//...
use App\MoonShine\Pages\CustomPage;
//...
public function pages(): array
{
return [
CustomPage::make('Заголовок страницы', 'custom_page')
->setBreadcrumbs([
'#' => $this->title()
])
];
}
//...
Метод alias()
позволяет изменить псевдоним для экземпляра страницы.
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('Заголовок страницы')
->alias('custom-page')
];
}
use App\MoonShine\Pages\CustomPage;
//...
public function pages(): array
{
return [
CustomPage::make('Заголовок страницы')
->alias('custom-page')
];
}
//...
use App\MoonShine\Pages\CustomPage;
//...
public function pages(): array
{
return [
CustomPage::make('Заголовок страницы')
->alias('custom-page')
];
}
//...
use App\MoonShine\Pages\CustomPage;
//...
public function pages(): array
{
return [
CustomPage::make('Заголовок страницы')
->alias('custom-page')
];
}
//...
use App\MoonShine\Pages\CustomPage;
//...
public function pages(): array
{
return [
CustomPage::make('Заголовок страницы')
->alias('custom-page')
];
}
//...
Если вам нужно добавить страницу без создания класса, а просто указав blade-представление, рекомендуем использовать ViewPage
.
MenuItem::make(
'Пользовательская',
ViewPage::make()
->setTitle('Привет')
->setLayout('custom_layout')
->setContentView('my-form', ['param' => 'value'])
),
MenuItem::make(
'Пользовательская',
ViewPage::make()
->setTitle('Привет')
->setLayout('custom_layout')
->setContentView('my-form', ['param' => 'value'])
),
MenuItem::make(
'Пользовательская',
ViewPage::make()
->setTitle('Привет')
->setLayout('custom_layout')
->setContentView('my-form', ['param' => 'value'])
),
MenuItem::make(
'Пользовательская',
ViewPage::make()
->setTitle('Привет')
->setLayout('custom_layout')
->setContentView('my-form', ['param' => 'value'])
),
MenuItem::make(
'Пользовательская',
ViewPage::make()
->setTitle('Привет')
->setLayout('custom_layout')
->setContentView('my-form', ['param' => 'value'])
),
Вы можете отображать быструю страницу вне MoonShine, просто вернув ее в Контроллере.
class HomeController extends Controller
{
public function __invoke(Request $request): Page
{
$articles = Article::query()
->published()
->latest()
->take(6)
->get();
return ViewPage::make()
->setTitle('Добро пожаловать')
->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('Добро пожаловать')
->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('Добро пожаловать')
->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('Добро пожаловать')
->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('Добро пожаловать')
->setLayout('layouts.app')
->setContentView('welcome', ['articles' => $articles]);
}
}