PHP code example of smartystudio / laravelmenu

1. Go to this page and download the library: Download smartystudio/laravelmenu 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/ */

    

smartystudio / laravelmenu example snippets


SmartyStudio\LaravelMenu\MenuServiceProvider::class,

'Menu' => SmartyStudio\LaravelMenu\Facades\Menu::class,

@extends('app')

@section('contents')
    {!! Menu::render() !!}
@endsection

@push('scripts')
    {!! Menu::scripts() !!}
@endpush

use SmartyStudio\LaravelMenu\Models\Menu;
use SmartyStudio\LaravelMenu\Models\MenuItem;

// Get menu by ID
$menu = Menu::find(1);

// Get menu by Name
$menu = Menu::where('name','Test Menu')->first();

/**
 * Get menu by Name and the Items with eager loading.
 * This is RECOMENDED for better performance and less query calls.
 */
$menu = Menu::where('name','Test Menu')->with('items')->first();

// Get menu by ID
$menu = Menu::where('id', 1)->with('items')->first();

// Access by Model result
$public_menu = $menu->items;

// Convert it to Array
$public_menu = $menu->items->toArray();

// Using Helper 
$public_menu = Menu::getByName('Public'); // return array

use SmartyStudio\LaravelMenu\Facades\Menu;
...
/**
 * Parameter: Menu ID
 * Return:    Array
 */
$menuList = Menu::get(1);

use SmartyStudio\LaravelMenu\Facades\Menu;
...
/**
 * Parameter: Menu ID
 * Return:    Array
 */
$menuList = Menu::getByName('Admin');
bash
php artisan vendor:publish --provider="SmartyStudio\LaravelMenu\MenuServiceProvider"
bash
php artisan migrate