• Stars
    star
    234
  • Rank 167,679 (Top 4 %)
  • Language
    PHP
  • License
    MIT License
  • Created over 5 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

This Laravel Nova package allows you to create and manage menus and menu items.

Nova Menu Builder

Latest Version on Packagist Total Downloads

This Laravel Nova package allows you to create and manage menus and menu items.

Requirements

  • php: >=8.0
  • laravel/nova: ^4.0

Features

  • Menu management
  • Menu items management
    • Simple drag-and-drop nesting and re-ordering
  • Custom menu item types support
    • Ability to easily add select types
    • Ability to add custom fields
    • Use menubuilder:type command to easily create new types
  • Fully localizable

Screenshots

Menu Detail View

Menu Item Edit

Installation and Setup

Installing the package

Install the package in a Laravel Nova project via Composer, edit the configuration file and run migrations.

# Install the package
composer require outl1ne/nova-menu-builder

# Publish the configuration file and edit it to your preference
# NB! If you want custom table names, configure them before running the migrations.
php artisan vendor:publish --tag=nova-menu-builder-config

Register the tool with Nova in the tools() method of the NovaServiceProvider:

// in app/Providers/NovaServiceProvider.php

public function tools()
{
    return [
        // ...
        \Outl1ne\MenuBuilder\MenuBuilder::make(),

        // Optional customization
        ->title('Menus') // Define a new name for sidebar
        ->icon('adjustments') // Customize menu icon, supports heroicons
        ->hideMenu(false) // Hide MenuBuilder defined MenuSection.
    ];
}

Setting up

After publishing the configuration file, you have to make some required changes in the config:

# Choose table names of your liking by editing the two key/values:
'menus_table_name' => 'nova_menu_menus',
'menu_items_table_name' => 'nova_menu_menu_items',

# Define the locales for your project:
# If your project doesn't have localization, you can just leave it as it is.
# When there's just one locale, anything related to localization isn't displayed.
'locales' => ['en' => 'English'],

# Define the list of possible menus (ie 'footer', 'header', 'main-menu'):
'menus' => [
    // 'header' => [
    //     'name' => 'Header',
    //     'unique' => true,
    //     'menu_item_types' => []
    // ]
],

# If you're just setting up, this is probably of no importance to you,
# but later on, when you want custom menu item types with custom fields
# , you can register them here:
'menu_item_types' => [],

Next, just run the migrations and you're set.

# Run the automatically loaded migrations
php artisan migrate

Optionally publish migrations

This is only useful if you want to overwrite migrations and models. If you wish to use the menu builder as it comes out of the box, you don't need them.

# Publish migrations to overwrite them (optional)
php artisan vendor:publish --tag=nova-menu-builder-migrations

Usage

Locales configuration

You can define the locales for the menus in the config file, as shown below.

// in config/nova-menu.php

return [
  // ...
  'locales' => [
    'en' => 'English',
    'et' => 'Estonian',
  ],

  // or using a closure (not cacheable):

  'locales' => function() {
    return nova_lang_get_locales();
  }

  // or if you want to use a function, but still be able to cache it:

  'locales' => '\App\Configuration\NovaMenuConfiguration@getLocales',

  // or

  'locales' => 'nova_lang_get_locales',
  // ...
];

Custom menu item types

Menu builder allows you create custom menu item types with custom fields.

Create a class that extends the Outl1ne\MenuBuilder\MenuItemTypes\BaseMenuItemType class and register it in the config file.

// in config/nova-menu.php

return [
  // ...
  'menu_item_types' => [
    \App\MenuItemTypes\CustomMenuItemType::class,
  ],
  // ...
];

In the created class, overwrite the following methods:

/**
 * Get the menu link identifier that can be used to tell different custom
 * links apart (ie 'page' or 'product').
 *
 * @return string
 **/
public static function getIdentifier(): string {
    // Example usecase
    // return 'page';
    return '';
}

/**
 * Get menu link name shown in  a dropdown in CMS when selecting link type
 * ie ('Product Link').
 *
 * @return string
 **/
public static function getName(): string {
    // Example usecase
    // return 'Page Link';
    return '';
}

/**
 * Get list of options shown in a select dropdown.
 *
 * Should be a map of [key => value, ...], where key is a unique identifier
 * and value is the displayed string.
 *
 * @return array
 **/
public static function getOptions($locale): array {
    // Example usecase
    // return Page::all()->pluck('name', 'id')->toArray();
    return [];
}

/**
 * Get the subtitle value shown in CMS menu items list.
 *
 * @param $value
 * @param $data The data from item fields.
 * @param $locale
 * @return string
 **/
public static function getDisplayValue($value, ?array $data, $locale) {
    // Example usecase
    // return 'Page: ' . Page::find($value)->name;
    return $value;
}

/**
 * Get the enabled value
 *
 * @param $value
 * @param $data The data from item fields.
 * @param $locale
 * @return string
*/
public static function getEnabledValue($value, ?array $data, $locale)
{
  return true;
}

/**
 * Get the value of the link visible to the front-end.
 *
 * Can be anything. It is up to you how you will handle parsing it.
 *
 * This will only be called when using the nova_get_menu()
 * and nova_get_menus() helpers or when you call formatForAPI()
 * on the Menu model.
 *
 * @param $value The key from options list that was selected.
 * @param $data The data from item fields.
 * @param $locale
 * @return any
 */
public static function getValue($value, ?array $data, $locale)
{
    return $value;
}

/**
 * Get the fields displayed by the resource.
 *
 * @return array An array of fields.
 */
public static function getFields(): array
{
    return [];
}

/**
 * Get the rules for the resource.
 *
 * @return array A key-value map of attributes and rules.
 */
public static function getRules(): array
{
    return [];
}

/**
 * Get data of the link visible to the front-end.
 *
 * Can be anything. It is up to you how you will handle parsing it.
 *
 * This will only be called when using the nova_get_menu()
 * and nova_get_menus() helpers or when you call formatForAPI()
 * on the Menu model.
 *
 * @param null $data Field values
 * @return any
 */
public static function getData($data = null)
{
    return $data;
}

Returning the menus in a JSON API

nova_get_menus()

A helper function nova_get_menus is globally registered in this package which returns all the menus including their menu items in an API friendly format.

public function getMenus(Request $request) {
    $menusResponse = nova_get_menus();
    return response()->json($menusResponse);
}

Get single menu via identifier

// Available helpers
nova_get_menu_by_slug($menuSlug, $locale = null)
nova_get_menu_by_id($menuId, $locale = null)

To get a single menu, you can use the available helper functions.
Returns null if no menu with the identifier is found or returns the menu if it is found. If no locale is passed, the helper will automatically choose the first configured locale.

Credits

License

Nova Menu Builder is open-sourced software licensed under the MIT license.

More Repositories

1

nova-multiselect-field

A Laravel Nova package that adds a multiselect to Nova's arsenal of fields.
PHP
326
star
2

nova-sortable

This Laravel Nova package allows you to reorder models in a Nova resource's index view using drag & drop.
Vue
274
star
3

nova-settings

A Laravel Nova tool for editing custom settings using native Nova fields.
PHP
270
star
4

nova-translatable

A Laravel Nova package that allows you to make any input field translatable.
PHP
191
star
5

nova-page-manager

Static page and region manager for Laravel Nova - designed for headless CMS's.
PHP
177
star
6

nova-simple-repeatable

A Laravel Nova simple repeatable rows field.
Vue
73
star
7

nova-detached-filters

This Laravel Nova package allows you to detach filters from the filter dropdown and show them on a card
PHP
58
star
8

nova-tailwind

This Laravel Nova package loads the full Tailwind CSS in the Nova admin panel.
JavaScript
56
star
9

nova-media-field

Simple media field with multiple image support, image browsing and thumbnail generation
Vue
55
star
10

nova-notes-field

This Laravel Nova package adds a notes field to Nova's arsenal of fields.
PHP
49
star
11

nova-media-hub

This Laravel Nova package allows you to manage media and media fields.
PHP
44
star
12

nova-table-field

Table field for Laravel Nova
Vue
40
star
13

nova-translations-loader

This package helps with loading translations inside a Nova package.
PHP
39
star
14

nova-multiselect-filter

Multiselect filter for Laravel Nova.
Vue
38
star
15

nova-blog

A Laravel Nova package that allows you to create a blog, manage blogposts and posts' content.
PHP
36
star
16

nova-drafts

A Laravel Nova package that allows you to make drafts of your current resources.
PHP
29
star
17

nova-color-field

A Laravel Nova package that adds a color picker to Nova's arsenal of fields.
Vue
26
star
18

nova-input-filter

Simple Laravel Nova input filter. Works as additional search field out of the box.
PHP
22
star
19

laravel-scout-batch-searchable

This Laravel package allows for batching of Scout updates.
PHP
18
star
20

nova-locale-field

A Laravel Nova field that allows you to manage multiple localisations of a model.
Vue
17
star
21

nova-inline-text-field

This Laravel Nova package adds an inline text field to Nova's arsenal of fields.
Vue
17
star
22

nova-resizable

A simple tool to allow resizing of nova resource table.
JavaScript
16
star
23

nova-locale-manager

An extremely simple Laravel Nova tool for managing locales.
PHP
15
star
24

nova-lang

This Laravel Nova package allows you to sort Nova resource's index view and assign locales to resources
Vue
14
star
25

create-frontend

JavaScript
11
star
26

nova-redirects

Redirect manager for Laravel Nova
PHP
11
star
27

laravel-generate-storage-structure

This package generates the Laravel storage folder structure. Useful when mounting an empty directory to replace `storage/` in production or staging environments.
PHP
9
star
28

nova-grid

Allow placing fields in a grid formation using ->size() helpers.
Vue
8
star
29

nova-charcounted-fields

Mirror of elevate-digital/nova-charcounted-fields.
Vue
7
star
30

laravel-create-frontend

PHP
7
star
31

core-js

A collection of JS functionalities that we commonly need to use.
JavaScript
6
star
32

core-scss

This is a SCSS partial that provides some utility mixins and default styles that fit our workflow.
CSS
5
star
33

nova-trumbowyg-field

This Laravel Nova package adds a Trumbowyg field to Nova's arsenal of fields.
PHP
5
star
34

laravel-thumbor

PHP
5
star
35

stylelint-config-rules

This is a set of rules for StyleLint.
JavaScript
4
star
36

react-countdown

JavaScript
4
star
37

softreport-linux-client

Repository to retrieve version data from server and send it to SoftReport backend
JavaScript
4
star
38

eslint-config-rules

This is a set of rules for ESLint.
JavaScript
4
star
39

nova-tooltip-field

This Laravel Nova package adds a tooltip field to Nova's arsenal of fields.
Vue
3
star
40

laravel-elastic-logger

Package to listen to Laravel MessageLogged event and queue the log data to be sent to Elastic logs over API.
PHP
3
star
41

nova-currency-vat-field

A Laravel Nova Currency field extension with VAT toggle.
Vue
3
star
42

laravel-healthz

Health check route for Laravel application.
PHP
2
star
43

laravel-console-over-http

PHP
2
star
44

nova-openai

PHP
2
star
45

using-models-in-laravel-migrations

Article about how to use models in Laravel migrations
PHP
1
star
46

nova-account-settings

PHP
1
star
47

laravel-google-cloud-queues

Manage Google Cloud queues from Laravel app.
PHP
1
star
48

nova-release-tracking

Github Action to track nova releases
JavaScript
1
star
49

nova-translations-loader-php

A Laravel Nova package that simplifies the loading of translations inside other packages.
PHP
1
star