{"id":20523097,"url":"https://github.com/itstructure/laravel-multi-menu","last_synced_at":"2025-04-14T03:06:08.378Z","repository":{"id":56994557,"uuid":"138891138","full_name":"itstructure/laravel-multi-menu","owner":"itstructure","description":"Widget for rendering multilevel menu for Laravel Framework","archived":false,"fork":false,"pushed_at":"2025-03-01T01:27:38.000Z","size":65,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-04-14T03:06:01.382Z","etag":null,"topics":["laravel","menu","multilevel-menu"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/itstructure.png","metadata":{"files":{"readme":"README.md","changelog":"changelog.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-06-27T14:14:34.000Z","updated_at":"2025-03-01T01:30:26.000Z","dependencies_parsed_at":"2023-02-14T18:46:11.212Z","dependency_job_id":null,"html_url":"https://github.com/itstructure/laravel-multi-menu","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/itstructure%2Flaravel-multi-menu","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/itstructure%2Flaravel-multi-menu/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/itstructure%2Flaravel-multi-menu/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/itstructure%2Flaravel-multi-menu/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/itstructure","download_url":"https://codeload.github.com/itstructure/laravel-multi-menu/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248813796,"owners_count":21165633,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["laravel","menu","multilevel-menu"],"created_at":"2024-11-15T22:37:55.787Z","updated_at":"2025-04-14T03:06:08.371Z","avatar_url":"https://github.com/itstructure.png","language":"PHP","readme":"# Laravel MultiMenu widget\n\n## 1 Introduction\n\n[![Latest Stable Version](https://poser.pugx.org/itstructure/laravel-multi-menu/v/stable)](https://packagist.org/packages/itstructure/laravel-multi-menu)\n[![Latest Unstable Version](https://poser.pugx.org/itstructure/laravel-multi-menu/v/unstable)](https://packagist.org/packages/itstructure/laravel-multi-menu)\n[![License](https://poser.pugx.org/itstructure/laravel-multi-menu/license)](https://packagist.org/packages/itstructure/laravel-multi-menu)\n[![Total Downloads](https://poser.pugx.org/itstructure/laravel-multi-menu/downloads)](https://packagist.org/packages/itstructure/laravel-multi-menu)\n[![Build Status](https://scrutinizer-ci.com/g/itstructure/laravel-multi-menu/badges/build.png?b=master)](https://scrutinizer-ci.com/g/itstructure/laravel-multi-menu/build-status/master)\n[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/itstructure/laravel-multi-menu/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/itstructure/laravel-multi-menu/?branch=master)\n\nThis widget is to display a multi level menu. There can be nested sub-menus. Used for Laravel framework.\n\nThe widget uses data from the **database**, in which there are, in addition to the primary keys, also the parent keys.\n\nData from the **database** is taken from a model and must be instance of **Illuminate\\Database\\Eloquent\\Collection**.\n\n![Multi level menu example scheme](https://github.com/itstructure/laravel-multi-menu/blob/master/ML_menu_en.jpg)\n\n## 2 Requirements\n\n- laravel 5.5+ | 6+ | 7+ | 8+ | 9+ | 10+ | 11+ | 12+\n- php \u003e= 7.1.0\n- composer\n\n## 3 Installation\n\n### 3.1 General from remote repository\n\nVia composer:\n\n`composer require itstructure/laravel-multi-menu \"~2.0.9\"`\n\n### 3.2 If you are testing this package from local server directory\n\nIn application `composer.json` file set the repository, like in example:\n\n```json\n\"repositories\": [\n    {\n        \"type\": \"path\",\n        \"url\": \"../laravel-multi-menu\",\n        \"options\": {\n            \"symlink\": true\n        }\n    }\n],\n```\n\nHere,\n\n**../laravel-multi-menu** - directory name, which has the same directory level as application and contains multi menu package.\n\nThen run command:\n\n`composer require itstructure/laravel-multi-menu:dev-master --prefer-source`\n\n### 3.3 Publish in application\n\n- To publish all parts run command:\n    \n    `php artisan multimenu:publish`\n\n- To publish only config run command:\n\n    `php artisan multimenu:publish --only=config`\n    \n    It stores `multimenu.php` config file to `config` folder.\n        \n- To publish only views run command:\n            \n    `php artisan multimenu:publish --only=views`\n    \n    It stores view files to `resources/views/vendor/multimenu` folder.\n\n- Else you can use `--force` argument to rewrite already published files.\n\nOr another variant:\n\n`php artisan vendor:publish --provider=\"Itstructure\\MultiMenu\\MultiMenuServiceProvider\"`\n\n## 4 Usage\n\n### 4.1 Simple variant\n\n#### Config part\n\n```php\nreturn [\n    'primaryKeyName' =\u003e 'id', // Editable\n    'parentKeyName' =\u003e 'parent_id', // Editable\n    'mainTemplate' =\u003e 'main', // Editable\n    'itemTemplate' =\u003e 'item', // Editable\n];\n```\n\n#### View template part\n\n```php\n@php\n$multiOptions = [ // Editable\n    'config' =\u003e config('multimenu'),\n    'data' =\u003e $pages\n];\n@endphp\n```\n\n```php\n@multiMenu($multiOptions)\n```\n    \nHere, `$pages` - is from controller part, for example `$pages = Page::all();`. Must be instance of `Illuminate\\Database\\Eloquent\\Collection`.\n\n### 4.2 Addition config options and data\n\n#### Config part\n\nThere is an example to set item blade templates for 3 levels:\n\n```php\nreturn [\n    'primaryKeyName' =\u003e 'id',\n    'parentKeyName' =\u003e 'parent_id',\n    'mainTemplate' =\u003e 'main',\n    'itemTemplate' =\u003e [\n        'levels' =\u003e [\n            'item',\n            'item',\n            'item_new',\n        ]\n    ],\n];\n```\n\nYou can set `mainTemplate` by analogy.\n\n#### Blade templates\n\nExample of a custom changed blade template file `item.blade`:\n\n```php\n\u003cli\u003e\n    \u003ca href=\"{{ $data-\u003eicon }}\"\u003e\n        Initial item Id {{ $data-\u003eid }} {{ isset($addition) ? ' | ' . $addition : '' }}\n    \u003c/a\u003e\n\u003c/li\u003e\n```\n\nExample of a custom changed blade template file `item_new.blade`:\n\n```php\n\u003cli\u003e\n    \u003ca href=\"{{ $data-\u003eicon }}\" style=\"color: green; font-weight: bold;\"\u003e\n        New item Id {{ $data-\u003eid }} {{ isset($addition) ? ' | ' . $addition : '' }}\n    \u003c/a\u003e\n\u003c/li\u003e\n```\n\n#### Addition data\n\nExample in a template file:\n\n```php\n@php\n$multiOptions = [\n    'config' =\u003e config('multimenu'),\n    'data' =\u003e $pages,\n    'additionData' =\u003e [\n        'levels' =\u003e [\n            0 =\u003e [],\n            1 =\u003e ['addition' =\u003e 'addition string']\n        ]\n    ]\n];\n@endphp\n```\n\n```php\n@multiMenu($multiOptions)\n```\n\n### 4.3 Database table structure example\n\n`Table \"catalogs\"`\n\n    | id  | parent_id |   title    | ... |\n    |-----|-----------|------------|-----|\n    |  1  |   NULL    |   item 1   | ... |\n    |  2  |   NULL    |   item 2   | ... |\n    |  3  |   NULL    |   item 3   | ... |\n    |  4  |   NULL    |   item 4   | ... |\n    |  5  |   NULL    |   item 5   | ... |\n    |  6  |     2     |  item 2.1  | ... |\n    |  7  |     2     |  item 2.2  | ... |\n    |  8  |     7     | item 2.2.1 | ... |\n    |  9  |     7     | item 2.2.2 | ... |\n    |  10 |     7     | item 2.2.3 | ... |\n    | ... |    ...    |     ...    | ... |\n\n\n## 5 Prevention of collisions\n\n### 5.1 Before save model\n\nTo prevent the entry of the wrong parent identifier (for example, the new number that is a child in a subordinate chain of nested records):\n\nUse static method `checkNewParentId(Model $mainModel, int $newParentId... e.t.c)`\n\nHere are the required parameters:\n\n**$mainModel** - current model record, in which the parent id will be changed for new value.\n\n**$newParentId** - new parent id, which must be verified.\n\n### 5.2 After delete model\n\nTo prevent breaks in the chain of subject submissions:\n\nUse static method `afterDeleteMainModel(Model $mainModel... e.t.c)`\n\nHere is the required parameter:\n\n**$mainModel** - deleted model record.\n\nThis function will rebuild the chain.\n\n## License\n\nCopyright © 2018-2025 Andrey Girnik girnikandrey@gmail.com.\n\nLicensed under the [MIT license](http://opensource.org/licenses/MIT). See LICENSE.txt for details.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fitstructure%2Flaravel-multi-menu","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fitstructure%2Flaravel-multi-menu","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fitstructure%2Flaravel-multi-menu/lists"}