cube-agency / arbory-menu
Menu module for Arbory CMS
v0.2
2020-04-28 10:41 UTC
Requires
- arbory/arbory: ^1.0
This package is auto-updated.
Last update: 2024-11-11 22:21:22 UTC
README
CMS module for creating menus
Installation
Require cube-agency/arbory-menu
$ composer require cube-agency/arbory-menu
Run migrations (creates menus
and menu_items
tables)
$ php artisan migrate
Enable module by adding to config config/arbory.php
and register routes in routes/admin.php
'menu' => [ ... \CubeAgency\ArboryMenu\Http\Controllers\Admin\MenuController::class ]
Admin::modules()->register(\CubeAgency\ArboryMenu\Http\Controllers\Admin\MenuController::class);
Example usage
-
Create new menu called "Main menu (EN)" via admin module
-
Add
main_menu_id
field to LanguagePage using laravel migrations -
Add select field under LanguagePage definition of fields in
routes/pages.php
Page::register(LanguagePage::class) ->fields(function (FieldSet $fieldSet) { ... $fieldSet->select('main_menu_id')->options( ... ); })
-
Add relation to Pages/LanguagePage.php
public function mainMenu(): BelongsTo { return $this->belongsTo(\CubeAgency\ArboryMenu\Menu\Menu::class); }
-
Get and assign menu items in your view composer
public function compose(View $view): void { ... $view->with([ ... 'mainMenuItems' => $languageNode->content->mainMenu->getPreparedItems() ]); }
-
Output menu in layout view
<ul> @foreach($mainMenuItems as $item) <li class="{{$item['active'] ? 'active' : ''}}"> <a href="{{$item['link']}}"> {{$item['name']}} </a> </li> @endforeach </ul>