From 8c57284c30e533f46a68dd1b3726cdc096204ceb Mon Sep 17 00:00:00 2001 From: Herbert Maschke Date: Tue, 19 Jan 2021 17:24:30 +0100 Subject: [PATCH] Add ability to use Bootstrap 5 (#279) Introduced a setting 'laravel-menu.settings.default.data_toggle_attribute' which needs to be set to 'data-bs-toggle' when using bootstrap 5 (currently in beta). Co-authored-by: Herbert Maschke --- README.md | 4 +++- src/Lavary/Menu/ServiceProvider.php | 4 ++++ .../Menu/resources/views/bootstrap-navbar-items.blade.php | 2 +- src/config/settings.php | 1 + 4 files changed, 9 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index a650c1e..5055f69 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ [![License](https://poser.pugx.org/lavary/laravel-menu/license.svg)](https://packagist.org/packages/lavary/laravel-menu) -A quick and easy way to create menus in [Laravel 6](http://laravel.com/) +A quick and easy way to create menus in [Laravel 6, 7 and 8](http://laravel.com/) __For Laravel 4.x, check [version 1.5.0](https://github.com/lavary/laravel-menu/tree/v1.5.0)__ @@ -1359,6 +1359,8 @@ This is how your Bootstrap code is going to look like: ``` +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`. + #### Adding class attributes to child items Like adding a class to the menu `ul` and `ol`, classes can be added the submenu too. The three parameters to `asUl` are arrays as follows: diff --git a/src/Lavary/Menu/ServiceProvider.php b/src/Lavary/Menu/ServiceProvider.php index 1cc7826..f73fa2e 100644 --- a/src/Lavary/Menu/ServiceProvider.php +++ b/src/Lavary/Menu/ServiceProvider.php @@ -80,6 +80,10 @@ protected function bladeDirectives() Blade::directive('lm_endattrs', function ($expression) { return ''; }); + + Blade::directive('data_toggle_attribute', function ($expression) { + return config('laravel-menu.settings.default.data_toggle_attribute'); + }); } /** diff --git a/src/Lavary/Menu/resources/views/bootstrap-navbar-items.blade.php b/src/Lavary/Menu/resources/views/bootstrap-navbar-items.blade.php index 47909dd..7623417 100644 --- a/src/Lavary/Menu/resources/views/bootstrap-navbar-items.blade.php +++ b/src/Lavary/Menu/resources/views/bootstrap-navbar-items.blade.php @@ -1,6 +1,6 @@ @foreach($items as $item)
  • hasChildren()) class="nav-item dropdown" @endif @lm_endattrs> - @if($item->link) link) @if($item->hasChildren()) class="nav-link dropdown-toggle" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" @else class="nav-link" @endif @lm_endattrs href="{!! $item->url() !!}"> + @if($item->link) link) @if($item->hasChildren()) class="nav-link dropdown-toggle" role="button" @data_toggle_attribute="dropdown" aria-haspopup="true" aria-expanded="false" @else class="nav-link" @endif @lm_endattrs href="{!! $item->url() !!}"> {!! $item->title !!} @if($item->hasChildren()) @endif diff --git a/src/config/settings.php b/src/config/settings.php index 2dadb32..5fbe5ac 100644 --- a/src/config/settings.php +++ b/src/config/settings.php @@ -9,5 +9,6 @@ 'cascade_data' => true, 'rest_base' => '', // string|array 'active_element' => 'item', // item|link + 'data-toggle-attribute' => 'data-toggle', ), );