lavary / laravel-menu

A quick way to create menus in Laravel
MIT License
1.16k stars 233 forks source link

In case you are using bootstrap 5 (currently in beta) you need to set the data-toggle-attribute option from data-toggle to data-bs-toggle in your config/laravel-menu/settings.php. #302

Open mtkumar82 opened 1 year ago

mtkumar82 commented 1 year ago

In case you are using bootstrap 5 (currently in beta) you need to set the data-toggle-attribute option from data-toggle to data-bs-toggle in your config/laravel-menu/settings.php.

I tried to change the value from 'data-toggle-attribute'=>'data-bs-toggle' in same file metioned above, But its not getting changed there.

return array( 'default' => array( 'auto_activate' => true, 'activate_parents' => true, 'active_class' => 'active', 'restful' => false, 'cascade_data' => true, 'rest_base' => '', // string|array 'active_element' => 'item', // item|link 'data_toggle_attribute' => 'data-bs-toggle', ),
);

Can you please help me what changes I need to do more for this one?

Thanks

reidsneo commented 1 year ago

Hi, that was correct but if you use config to draw the menu, can you give snip how you draw the menu?

I use following code to draw menu for bootstrap 5.2.3 it work out of the box

menu.blade.php

@foreach($items as $item)
  <li class="nav-item">
    <a class="nav-link @if(!$item->hasChildren()) menu-link @endif {{ $item->active ? 'active' : '' }}"
    @if($item->hasChildren()) data-bs-toggle="collapse" role="button" @endif
    @if(Str::contains($item->url(),"#")) href="#{!! explode("#",$item->url())[1] !!}" aria-controls="{!! explode("#",$item->url())[1] !!}" @else href="{!! $item->url() !!}" aria-controls="" @endif>
    @if($item->icon != null) <i class="{!! $item->icon !!}"></i> @endif
    @if($item->hasParent()) {!! $item->caption !!} @else <span>{!! $item->caption !!}</span>  @endif</a>
        @if($item->hasChildren())
        <div class="collapse menu-dropdown {{ $item->active ? 'show' : '' }}" @if(Str::contains($item->url(),"#")) id="{!! explode("#",$item->url())[1] !!}" @endif>
            <ul class="nav nav-sm flex-column">
                @include('theme::views.backend.menu', ['items' => $item->children()])
            </ul>
        @endif
    </li>
@endforeach

in main layout you need to call the menu.blade.php

<ul class="navbar-nav" id="navbar-nav">
            <li class="menu-title"><span></span></li>
            @include('theme::views.backend.menu', ['items' => $MenuBackend->roots()])
            </ul>