Laravel-adminlte: get error when set to layout_topnav

Created on 19 Mar 2020  路  10Comments  路  Source: jeroennoten/Laravel-AdminLTE

when i set

in adminlte.php
'layout_topnav' => true,

got this error

Undefined index: top_nav_class (View: .../vendor/jeroennoten/laravel-adminlte/resources/views/partials/menu-item-top-nav.blade.php)

bug

All 10 comments

Same Issue here, It was working till i didnt update it !

Error Started when i updated Admin Lte with composer update !

I will check this later.

when i place this to $menu array

'topnav' => true

error was gone

[ 'text' => 'blog', 'url' => 'admin/blog', 'topnav' => true, ],

@batty211 I guessed this already, but it should work without any menu item too 馃槃

In my last version of the views of adminlte, the code to menu-item-top-nav.blade.php is:

@if(config('adminlte.layout_topnav') or (isset($item['topnav']) && $item['topnav']))
@if (isset($item['search']) && $item['search'])
<form action="{{ $item['href'] }}" method="{{ $item['method'] }}" class="form-inline ml-2 mr-2">
<div class="input-group">
<input class="form-control form-control-navbar" type="search" name="{{
$item['input_name'] }}" placeholder="{{ $item['text'] }}" aria-label="{{ $item['aria-label'] ?? $item['text'] }}">
<div class="input-group-append">
<button class="btn btn-navbar" type="submit">
<i class="fas fa-search"></i>
</button>
</div>
</div>
</form>
@elseif (is_array($item))
<li @if (isset($item['id'])) id="{{ $item['id'] }}" @endif class="nav-item {{ $item['top_nav_class'] }}">
<a class="nav-link @if (isset($item['submenu']))dropdown-item dropdown-toggle @endif" href="{{ $item['href'] }}"
@if (isset($item['submenu'])) data-toggle="dropdown" @endif
@if (isset($item['target'])) target="{{ $item['target'] }}" @endif
>
<i class="{{ $item['icon'] ?? 'far fa-fw fa-circle' }} {{ isset($item['icon_color']) ? 'text-' . $item['icon_color'] : '' }}"></i>
{{ $item['text'] }}
@if (isset($item['label']))
<span class="badge badge-{{ $item['label_color'] ?? 'primary' }}">{{ $item['label'] }}</span>
@endif
</a>
@if (isset($item['submenu']))
<ul class="dropdown-menu border-0 shadow">
@each('adminlte::partials.menu-item-sub-top-nav', $item['submenu'], 'item')
</ul>
@endif
</li>
@endif
@endif

The error persist same after composer update, with config layout_topnav => true,:
FacadeIgnitionExceptionsViewException
Undefined index: top_nav_class (View: C:projectresourcesviews/vendor/adminlte/partials/menu-item-top-nav.blade.php:13)

Some of the $item array elements don't exist and that throws an error because they are not checked with isset().

Example how to fix:

Instead of

{{$item['top_nav_class']}}

put

@if(isset($item['top_nav_class'])) {{ $item['top_nav_class'] }} @endif

or alternatively a little shorter

@isset($item['top_nav_class']) {{ $item['top_nav_class'] }} @endisset

Repeat that for all the other unchecked $item references that throw an error.

There is also a even shorter version, {{$item['top_nav_class'] ?? ''}}.

The error was given, if an menu entry has a "header" entry. The top_nav_class is not available on header menu.

I have changed the logic, that header menu entries will be not shown on the topnav.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rafayet-monon picture rafayet-monon  路  3Comments

eraporsmk picture eraporsmk  路  5Comments

bbdangar picture bbdangar  路  5Comments

santiagoferraz picture santiagoferraz  路  5Comments

claytongf picture claytongf  路  5Comments