API

Namespace for all package classes: Atorscho\Menus.

The Laravel Facade Menu is just an instance (singleton) of this class.


public function all(string $identifier = ''): array;

If no parameter specified, the method will return an array of all registered menus with their identifiers as array key.

If $identifier exists it will return the actual menu, otherwise an empty array.


public function register(string $identifier, $title, string $url = '', array $children = [], array $fields = []): Menu;

Register new menu by specifying its identifier, title and URL.

There are two ways of passing arguments. First as named parameters, the other one as an array:

Menu::register('primary', 'Home', '/home');

Menu::register('primary', [
  'title' => 'Home',
  'url'   => '/home'
]);

public function build(string $identifier, callable $items): Menu;

There is also another way of registering menus — by using the Menu Builder.

Simply give the menu its unique identifier and a callback where you add all menu items.

The Builder::add() method has the same signature as Menu::register() except for the identifier since it is provided by the Menu::build() method.

Menu::build('secondary', function (Builder $builder) {
  $builder->add('Products', '/products');
});

public function exists(string $identifier): bool;

The method checks whether the specified menu identifier exists.


public function count(string $identifier = ''): int;

If $identifier is specified, the method will count all its items, including nested ones.

If no parameter specified, the method will return a total number of all registered menus' items.


public function getChildren(string $identifier): array;

This method only returns menu's child elements.


public function toArray($values = []): array;

Returns all registered menus as arrays.

Item

public function isActive(): bool;

Returns true if the item is the current page. If item is nested (custom field 'nested' => false, the item will not put its parent into active state.


public function activeAttr(string $className = ''): string;

This method outputs an HTML class attribute with the active class name: class="active".

The active class name may be changed in the configuration file config/menus.php.


public function activeClass(string $className = ''): string;

Simply returns the active class name if the item is currently open page.


public function active(string $className = ''): string;

An alias for Item::activeAttr().


public function appendChild(Item $child);

Adds a new child to the item.


public function hasChildren(): bool;

This method checks if the item has child elements.


public function hasField(string $field): bool;

Checks if the item has a specific custom field.


public function hasNotField(string $field): bool;

Alias for ! Item::hasField().


public function hasIcon(): bool;

Checks if the item has an icon field.


public function hasNotIcon(): bool;

Alias for ! Item::hasIcon().


public function isNested(): bool;

Checks whether the is nested or not.


public function isNotNested(): bool;

Alias for ! Item::isNested().

results matching ""

    No results matching ""