3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【Laravel AdminLTE】headerをカスタマイズする①

Posted at

やりたいこと

https://adminlte.io/themes/v3/

このベルアイコンとnotificationを表示したい

調査

navbar.blade.php
    {{-- Navbar right links --}}
    <ul class="navbar-nav ml-auto">
        {{-- Custom right links --}}
        @yield('content_top_nav_right')

        {{-- Configured right links --}}
        @each('adminlte::partials.navbar.menu-item', $adminlte->menu('navbar-right'), 'item')

        {{-- User menu link --}}
        @if(Auth::user())
            @if(config('adminlte.usermenu_enabled'))
                @include('adminlte::partials.navbar.menu-item-dropdown-user-menu')
            @else
                @include('adminlte::partials.navbar.menu-item-logout-link')
            @endif
        @endif

        {{-- Right sidebar toggler link --}}
        @if(config('adminlte.right_sidebar'))
            @include('adminlte::partials.navbar.menu-item-right-sidebar-toggler')
        @endif
    </ul>

@eachって初めて見た

Bladeの@eachディレクティブを使い、ループとビューの読み込みを組み合わせられます

@each('view.name', $jobs, 'job')

@each('adminlte::partials.navbar.menu-item', $adminlte->menu('navbar-right'), 'item')

view.name
adminlte::partials.navbar.menu-item

$jobs
$adminlte->menu('navbar-right')

job
item

$adminlte->menu('navbar-right')の登録の数だけ、$itemに代入してadminlte::partials.navbar.menu-itemを繰り返すということっぽい

今回はnavbar-rightに表示させたいのでnavbar-rightを調べてみる

vendor/jeroennoten/laravel-adminlte/src/AdminLte.php
        $this->menuFilterMap = [
            'sidebar'      => [$this, 'sidebarFilter'],
            'navbar-left'  => [$this, 'navbarLeftFilter'],
            'navbar-right' => [$this, 'navbarRightFilter'],
            'navbar-user'  => [$this, 'navbarUserMenuFilter'],
        ];

navbarRightFilterって何だろう

vendor/jeroennoten/laravel-adminlte/src/AdminLte.php
    /**
     * Filter method used to get the top navbar right menu items.
     *
     * @param mixed $item A menu item
     * @return bool
     */
    private function navbarRightFilter($item)
    {
        return MenuItemHelper::isNavbarRightItem($item);
    }

vendor/jeroennoten/laravel-adminlte/src/Helpers/MenuItemHelper.php

    /**
     * Check if a menu item belongs to the right section of the navbar.
     *
     * @param mixed $item
     * @return bool
     */
    public static function isNavbarRightItem($item)
    {
        return self::isValidNavbarItem($item) &&
               isset($item['topnav_right']) &&
               $item['topnav_right'];
    }
vendor/jeroennoten/laravel-adminlte/src/Helpers/MenuItemHelper.php
    /**
     * Check if a menu item is valid for the navbar section.
     *
     * @param mixed $item
     * @return bool
     */
    public static function isValidNavbarItem($item)
    {
        return self::isValidSidebarItem($item) && ! self::isHeader($item);
    }
vendor/jeroennoten/laravel-adminlte/src/Helpers/MenuItemHelper.php
    /**
     * Check if a menu item is valid for the sidebar section.
     *
     * @param mixed $item
     * @return bool
     */
    public static function isValidSidebarItem($item)
    {
        return self::isHeader($item) ||
               self::isSearchBar($item) ||
               self::isSubmenu($item) ||
               self::isLink($item);
    }

表示先のviewが以下だから

menu-item.blade.php
@inject('menuItemHelper', \JeroenNoten\LaravelAdminLte\Helpers\MenuItemHelper)

@if ($menuItemHelper->isSearchBar($item))

    {{-- Search form --}}
    @include('adminlte::partials.navbar.menu-item-search-form')

@elseif ($menuItemHelper->isSubmenu($item))

    {{-- Dropdown menu --}}
    @include('adminlte::partials.navbar.menu-item-dropdown-menu')

@elseif ($menuItemHelper->isLink($item))

    {{-- Link --}}
    @include('adminlte::partials.navbar.menu-item-link')

@endif

isSubmenu() === trueになるようにすればいいんだろうな

vendor/jeroennoten/laravel-adminlte/src/Helpers/MenuItemHelper.php
    /**
     * Check if a menu item is a submenu.
     *
     * @param mixed $item
     * @return bool
     */
    public static function isSubmenu($item)
    {
        return isset($item['text']) &&
               isset($item['submenu']) &&
               is_array($item['submenu']);
    }

$itemtextsubmenuを定義して
submenuは配列にすればいいと

config/adminlte.php
    'menu' => [
        /* 追加ここから */
        [
            'topnav_right' => true,
            'text' => '',
            'icon' => 'far fa-bell',
            'submenu' => [
                [
                    'text' => 'menu1',
                    'url' => '#',
                ],
                [
                    'text' => 'menu2',
                    'url' => '#',
                ],
            ],
        ],
        /* 追加ここまで */
    ],

次は件数表示だ。続く

3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?