Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using blades #7

Merged
merged 2 commits into from
Oct 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 19 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@ This tool allows you to create menus in Laravel Nova

<img width="1439" alt="menu builder Home" src="https://user-images.githubusercontent.com/42798230/50765532-7632ea80-1276-11e9-8fed-ec1f6d53983a.png">


<img width="1439" alt="Menu Builder Items" src="https://user-images.githubusercontent.com/42798230/50765390-06bcfb00-1276-11e9-9e82-fd7956507c78.png">


## Installation

You can install the package in to a Laravel app that uses [Nova](https://nova.laravel.com) via composer:
Expand All @@ -23,7 +21,6 @@ php artisan vendor:publish --tag=menu-builder-migration
php artisan migrate
```


## Usage

Next up, you must register the tool with Nova. This is typically done in the tools method of the NovaServiceProvider.
Expand All @@ -46,9 +43,9 @@ public function tools()

There are three helpers built in for your blades

* **menu_builder('slug')**.
- **menu_builder('slug')**.

Creates an html menu for given slug. Extra options are not required. By default tags are `ul` and `li`, and without html classes.
Creates an html menu for given slug. Extra options are not required. By default tags are `ul` and `li`, and without html classes.

```php
{!! menu_builder('main') !!}
Expand All @@ -58,28 +55,38 @@ There are three helpers built in for your blades
{!! menu_builder('main', 'parent-class', 'child-class', 'dl', 'dd') !!}
```

* **menu_name('slug')**.
- **menu_name('slug')**.

Returns the name of the menu for a given slug.
Returns the name of the menu for a given slug.

```php
{{ menu_name('main') }}
```

* **menu_json('slug')**.
- **menu_json('slug')**.

Returns a json with all items for given slug.
Returns a json with all items for given slug.

```php
{!! menu_json('main') !!}
```

## Example using blade.

```blade
@foreach (getMenuBySlug('header')->parentItems as $menuItem)
@include('menu-builder::menu-item', [
'menu' => $menuItem,
'active_top_class' => 'active',
'active_child_class' => 'active',
])
@endforeach
```

## Localization

Set your translations in the corresponding xx.json file located in /resources/lang/vendor/nova


```json
"Menu Builder": "Menu Builder",
"Menu Items": "Menu Items",
Expand Down Expand Up @@ -115,7 +122,6 @@ Set your translations in the corresponding xx.json file located in /resources/la
"Disabled": "Disabled"
```


## Changelog

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.
Expand All @@ -136,8 +142,8 @@ Our address is: Infinety - Calle Comedias, 8 Floor 3, Suite 5 46003 Valencia (Sp

## Credits

- [Eric Lagarda](https://github.com/Krato)
- [Ralph Huwiler (vue-nestable)](https://github.com/rhwilr/vue-nestable)
- [Eric Lagarda](https://github.com/Krato)
- [Ralph Huwiler (vue-nestable)](https://github.com/rhwilr/vue-nestable)

## License

Expand Down
20 changes: 20 additions & 0 deletions resources/views/menu-item.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
@php

$menu_class = $active_top_class ?? 'menu-item-has-children';
$child_class = $active_child_class ?? ' current-menu-item';

$has_children = count($menu->children) > 0 ? $menu_class : false;
$is_active = set_active($menu->type == 'route' ? $menu->route : $menu->link, $child_class);

@endphp
<li class="{{$has_children . $is_active}}">
<a href="{{$menu->link}}" target="{{$menu->target}}">{{ $menu->name }}</a>
@if($has_children)
<ul class="sub-menu">
@foreach ($menu->children as $subMenu)
@include('front.parts.menu_item', ['menu' => $subMenu])
@endforeach
</ul>
@endif
{{ $slot ?? '' }}
</li>
11 changes: 11 additions & 0 deletions src/Http/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@

use Infinety\MenuBuilder\Http\Models\Menu;

if (!function_exists('getMenuBySlug')) {
function getMenuBySlug($slug)
{
return Menu::whereHas('parentItems', function ($query) {
$query->with('children')
->where('enabled', 1)
->orderBy('order', 'asc');
})->whereSlug($slug)->first();
}
}

if (!function_exists('menu_builder')) {

/**
Expand Down