加入body class至html,自動帶入目前的路由名稱及語系

This commit is contained in:
kroutony 2020-02-22 17:07:01 +08:00
parent a90b5d19e8
commit 0d99af2fef
3 changed files with 27 additions and 2 deletions

View File

@ -0,0 +1,23 @@
<?php
namespace App\Presenters;
use Route;
class BodyClassPresenter
{
public function getRouteName()
{
return str_replace('.', '-', Route::currentRouteName());
}
public function print()
{
$classes =
[
$this->getRouteName(),
'lang-' . app()->getLocale()
];
return implode(' ', $classes);
}
}

View File

@ -16,7 +16,8 @@
@show
@stack('admin-app-styles')
</head>
<body class="app admin-area sidebar-lg-show header-fixed sidebar-fixed aside-menu-fixed footer-fixed">
@inject('bodyClassPresenter', App\Presenters\BodyClassPresenter)
<body class="app admin-area sidebar-lg-show header-fixed sidebar-fixed aside-menu-fixed footer-fixed {{ $bodyClassPresenter->print() }}">
<header id="app-header" class="app-header navbar">
<button class="navbar-toggler sidebar-toggler d-lg-none mr-auto" type="button" data-toggle="sidebar-show">
<span class="navbar-toggler-icon"></span>

View File

@ -17,7 +17,8 @@
@show
@stack('app-styles')
</head>
<body>
@inject('bodyClassPresenter', App\Presenters\BodyClassPresenter)
<body class="{{ $bodyClassPresenter->print() }}">
@section('content-header')
@include('components.nav')
@show