2
Help us understand the problem. What are the problem?

More than 1 year has passed since last update.

posted at

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

やりたいこと

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' => '#',
                ],
            ],
        ],
        /* 追加ここまで */
    ],

次は件数表示だ。続く

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Sign upLogin
2
Help us understand the problem. What are the problem?