malith124/materialized-path 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

malith124/materialized-path

最新稳定版本:1.0.8

Composer 安装命令:

composer require malith124/materialized-path

包简介

Materialized path trait for Laravel 10

README 文档

README

Latest Stable Version Total Downloads Latest Unstable Version License

Installation

  1. Add langaner/materialized-path to composer.json.
"langaner/materialized-path": "dev-master"

2)Run composer update to pull down the latest version of the package.

3)Now open up app/config/app.php and add the service provider to your providers array.

Langaner\MaterializedPath\MaterializedPathServiceProvider::class,

4)Add the trait to model what need tree implementation

use \Langaner\MaterializedPath\MaterializedPathTrait;

Migrations

Table migration example page_table:

	Schema::create('page_table', function(Blueprint $table)
	{
		$table->engine = 'InnoDB';
		$table->increments('id');
		// parent id
        $table->integer('parent_id')->unsigned()->nullable();
        // depth path consisting of models id
        $table->string('path');
        // depth path consisting of models alias
        $table->string('real_path')->unique();
        // alias field
        $table->string('alias')->unique();
        // order position
        $table->integer('position')->default(0)->index();
        // depth level
        $table->integer('level')->default(0)->index();

		$table->foreign('parent_id')->references('id')->on('page_table')->onDelete('cascade');
	});

Available methods

	// Make model is root
	with(new Page())->makeRoot();

	// Make model first children by parent id
	with(new Page())->makeFirstChildOf($parentId);

	// Make model last children by parent id
	with(new Page())->makeLastChildOf($parentId);

	// Make previous sibling
	$page = Page::find(2);
	$page->makePreviousSiblingOf(Page::find(1));

	// Make next sibling
	$page = Page::find(2);
	$page->makeNextSiblingOf(Page::find(1));

	// Update model data
	$page = Page::find(1);
	$page->position = 2;
	with(new Page())->updateNode($page);

	// Get parent
	Page::find(1)->parent()->get();
	
	// Get sibling
	Page::find(1)->sibling()->get();

	// Get childrens by depth
	Page::find(1)->childrenByDepth()->get();

	// Get parents by depth
	Page::find(1)->parentByDepth()->get();

	// Descendant check
	Page::find(1)->isDescendantOf(Page::find(2));

	// Ancestor check
	Page::find(1)->isAncestorOf(Page::find(2));

	// Is leaf
	Page::find(1)->isLeaf();

	// All leafs of model
	Page::allLeaf();

	// All roots of model
	Page::allRoot();

	// Get exploded path
	Page::find(1)->getExplodedPath();

	// Build real path by entities
	with(new Page())->buildRealPath($ids);

	// Build model tree
	Page::find(1)->buildTree();

	// Build model tree by parent id
	Page::find(1)->buildChidrenTree();

Configuration

Publish assets php artisan vendor:publish

This command initialize config file, located under app/config/packages/langaner/materialized-path/materialized_path.php.

Set with_translations to true if you need translation in result model. This option required translation pack https://github.com/dimsav/laravel-translatable

统计信息

  • 总下载量: 13
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 7
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-01-18

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固