1. Go to this page and download the library: Download vespakoen/menu library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
Menu::handler('main')->hydrate(function()
{
return Page::with('translation')
->where('group', '=', 'main')
->get();
},
function($children, $item)
{
$children->add($item->translation->slug, $item->translation->name, Menu::items($item->as));
});
/* the hydrate method takes these arguments
$resolver Closure A callback to resolve results
$decorator Closure A callback that gets called for every result fetched from the resolver with the corresponding ItemList and result as the arguments
$idField integer (default = 'id') the property on the result that contains the id
$parentIdField integer (default = 'parent_id') the property on the result that contains the parent id
$parentId integer (default = 0) the parentId to start hydrating from
*/
Menu::find('users')
->add('users/create', 'Create new user');
Menu::breadcrumbs(function($itemLists)
{
return $itemLists[0]; // returns first match
})
->setElement('ol')
->addClass('breadcrumb');
// Get a MenuHandler instance that handles an ItemList named "main"
Menu::handler('main');
Menu::handler('main')->add('home', 'Homepage');
/* The add method takes these arguments
$url string The URL to another page
$title string The visible string on the link
$children (default = null) ItemList (optional) The children of this page
$link_attributes (default = array()) array (optional) HTML attributes for the <a> element
$item_attributes (default = array()) array (optional) HTML attributes for the list element (usually <li>)
$item_element (default = 'li') string (optional) The type of the list element
*/
Menu::handler('main')->raw('<img src="img/seperator.gif">');
/* The raw method takes these arguments
$html string The contents of the item
$children (default = null) ItemList (optional) The children of this item
$item_attributes (default = array()) array (optional) HTML attributes for the list element (usually <li>)
$item_element (default = 'li') string (optional) The type of the list element
*/
Menu::handler('main')
->add('home', 'Homepage', Menu::items()
->add('sub-of-home', 'Sub of homepage'));
/* The items method takes these arguments
$name (default = null) string (optional) The name (=identifier) of this ItemList
$attributes (default = array()) array (optional) HTML attributes for the ItemList element (usually <ul>)
$element (default = 'ul') string (optional) The type of the ItemList element
*/
echo Menu::handler('main');
// Is the same as
echo Menu::handler('main')->render();
shell
php artisan bundle:install menu
php artisan vendor:publish
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.