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

Add menu_name helper. #5

Merged
merged 1 commit into from
Apr 19, 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
14 changes: 11 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ public function tools()

## Helpers

There are two helpers built in for your blades
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.

Expand All @@ -58,7 +58,15 @@ There are two helpers built in for your blades
{!! menu_builder('main', 'parent-class', 'child-class', 'dl', 'dd') !!}
```

* **menu_json('slug')**.
* **menu_name('slug')**.

Returns the name of the menu for a given slug.

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

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

Returns a json with all items for given slug.

Expand Down
20 changes: 20 additions & 0 deletions src/Http/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,26 @@ function menu_builder($slug, $parentClass = null, $childClass = null, $parentTag
}
}

if (!function_exists('menu_name')) {

/**
* Return menu name as a string
*
* @param string $slug
*
* @return string
*/
function menu_name($slug)
{
$menu = Menu::whereSlug($slug)->first();
if (!$menu) {
return '';
}

return $menu->name;
}
}

if (!function_exists('menu_json')) {

/**
Expand Down