winponta/treevel
最新稳定版本:0.3.0
Composer 安装命令:
composer require winponta/treevel
包简介
Set of classes and traits to handle tree hierarchy in Laravel Eloquent Models
README 文档
README
Installation
-
Require this package in your composer.json file and run composer install (or run
composer require winponta/treeveldirectly):"winponta/treevel": "0.*"
-
Run copmposer:
composer update
Using
Enable your models to be ready to handle tree hierarchy records, using one of the traits of the package (for now only Parent tree model is available).
Parent tree model
Parent tree models are handled using parent id references.
Trait
<?php
...
class MyModel extends Eloquent {
use \Winponta\Treevel\Traits\ParentTreeModel;
Default properties
Parent primary key (parentIdField)
This property is used to resolve the parent table primary key. If it's null the Eloquent primaryKey model property is used. You can change this value customizing the database field name your table/collection is using. Do this by setting the property calling the setParentIdField method in the model __constructot:
<?php
...
class MyModel extends Eloquent {
use \Winponta\Treevel\Traits\ParentTreeModel;
public function __construct() {
$this->setParentIdField( 'pk_on_parent_table' );
}
Parent references (parentField)
The default field name used by the package to handle the reference value to the parent record is named parent_id, you can change this value customizing the database field name your table/collection is using. Do this by setting the property calling the setParentField method in the model __constructot:
<?php
...
class MyModel extends Eloquent {
use \Winponta\Treevel\Traits\ParentTreeModel;
public function __construct() {
$this->setParentField( 'my_father_id' );
}
Node level property (levelField)
This property controls the deep level of the node in the tree. The default field value used to handle this feature is named node_level, you can change this value customizing the database field name your table/collection is using. Do this by setting the property calling the setLevelField method in the model __constructot:
<?php
...
class MyModel extends Eloquent {
use \Winponta\Treevel\Traits\ParentTreeModel;
public function __construct() {
$this->setLevelField( 'depth' );
}
Retrieving the tree
getTree
Returns the full tree from database as a Eloquent Collection
- $options - An array with options to be appplied when recovering descendants
* where => [key, value] - recover only descendants the key matches the value
winponta/treevel 适用场景与选型建议
winponta/treevel 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 549 次下载、GitHub Stars 达 3, 最近一次更新时间为 2015 年 09 月 10 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 winponta/treevel 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 winponta/treevel 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 549
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 18
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Unknown
- 更新时间: 2015-09-10