LayoutBuilder

# Публикация шаблона

Для изменения структуры шаблона необходимо воспользоваться LayoutBuilder.

Первым делом нужно опубликовать класс по изменению шаблона, воспользовавшись консольной командой.

php artisan moonshine:publish

После публикации Layout, в директории app/MoonShine появится класс MoonShineLayout.php.

namespace App\MoonShine;
 
use MoonShine\Components\Layout\{Content,
Flash,
Footer,
Header,
LayoutBlock,
LayoutBuilder,
Menu,
Profile,
Search,
Sidebar};
use MoonShine\Components\When;
use MoonShine\Contracts\MoonShineLayoutContract;
 
final class MoonShineLayout implements MoonShineLayoutContract
{
public static function build(): LayoutBuilder
{
return LayoutBuilder::make([
Sidebar::make([
Menu::make()->customAttributes(['class' => 'mt-2']),
When::make(
static fn() => config('moonshine.auth.enable', true),
static fn() => [Profile::make(withBorder: true)]
),
]),
LayoutBlock::make([
Flash::make(),
Header::make([
Search::make(),
]),
Content::make(),
Footer::make()->copyright(fn (): string => <<<'HTML'
&copy; 2021-2023 Made with ❤️ by
<a href="https://cutcode.dev"
class="font-semibold text-primary hover:text-secondary"
target="_blank"
>
CutCode
</a>
HTML)->menu([
'https://moonshine.cutcode.dev' => 'Documentation',
]),
])->customAttributes(['class' => 'layout-page']),
]);
}
}

# Верхнее меню

По умолчанию в MoonShine есть компонент для верхнего меню. Давайте взглянем как в LayoutBuilder заменить Sidebar на TopBar.

namespace App\MoonShine;
 
use MoonShine\Components\Layout\{Content,
Flash,
Footer,
Header,
LayoutBlock,
LayoutBuilder,
Menu,
Profile,
Search,
TopBar};
use MoonShine\Components\When;
use MoonShine\Contracts\MoonShineLayoutContract;
 
final class MoonShineLayout implements MoonShineLayoutContract
{
public static function build(): LayoutBuilder
{
return LayoutBuilder::make([
TopBar::make([
Menu::make()->top(),
])
->actions([
When::make(
static fn() => config('moonshine.auth.enable', true),
static fn() => [Profile::make()]
)
]),
LayoutBlock::make([
Flash::make(),
Header::make([
Search::make(),
]),
Content::make(),
Footer::make()->copyright(fn (): string => <<<'HTML'
&copy; 2021-2023 Made with ❤️ by
<a href="https://cutcode.dev"
class="font-semibold text-primary hover:text-secondary"
target="_blank"
>
CutCode
</a>
HTML)->menu([
'https://moonshine.cutcode.dev' => 'Documentation',
]),
])->customAttributes(['class' => 'layout-page']),
]);
}
}