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

# やりたいこと
![https://adminlte.io/themes/v3/](https://i.gyazo.com/c28ac80d2181c2ae1bbdf2232276c1f0.png)

このベルアイコンと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`って初めて見た


https://readouble.com/laravel/5.5/ja/blade.html
>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`を繰り返すということっぽい

https://github.com/jeroennoten/Laravel-AdminLTE/wiki

今回は`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']);
    }
```

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

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

![](https://i.gyazo.com/65143fa4cf9650e3fbda29eb27c27eaf.png)

次は件数表示だ。続く