Внешний вид

LayoutBuilder

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

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

Первым шагом является публикация класса модификации шаблона с помощью консольной команды.

php artisan moonshine:publish layout
php artisan moonshine:publish layout

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

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

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']),
]);
}
}
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 имеет компонент верхнего меню. Давайте посмотрим, как заменить Sidebar на TopBar в LayoutBuilder.

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']),
]);
}
}
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']),
]);
}
}