2017 © Pedro Peláez
 

library treevel

Set of classes and traits to handle tree hierarchy in Laravel Eloquent Models

image

winponta/treevel

Set of classes and traits to handle tree hierarchy in Laravel Eloquent Models

  • Thursday, December 21, 2017
  • by nunomazer
  • Repository
  • 2 Watchers
  • 3 Stars
  • 190 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 2 Forks
  • 0 Open issues
  • 12 Versions
  • 1 % Grown

The README.md

treevel

Installation

  1. Require this package in your composer.json file and run composer install (or run composer require winponta/treevel directly):, (*1)

    "winponta/treevel": "0.*", (*2)

  2. Run copmposer:, (*3)

    composer update, (*4)

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)., (*5)

Parent tree model

Parent tree models are handled using parent id references., (*6)

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:, (*7)

<?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:, (*8)

<?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:, (*9)

<?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, (*10)

  • $options - An array with options to be appplied when recovering descendants

> * where => [key, value] - recover only descendants the key matches the value >, (*11)

The Versions

21/12 2017

dev-master

9999999-dev

Set of classes and traits to handle tree hierarchy in Laravel Eloquent Models

  Sources   Download

The Requires

 

20/12 2017

0.3.0

0.3.0.0

Set of classes and traits to handle tree hierarchy in Laravel Eloquent Models

  Sources   Download

The Requires

 

16/11 2016

dev-dev

dev-dev

Set of classes and traits to handle tree hierarchy in Laravel Eloquent Models

  Sources   Download

The Requires

 

16/11 2016

0.2.2

0.2.2.0

Set of classes and traits to handle tree hierarchy in Laravel Eloquent Models

  Sources   Download

The Requires

 

17/10 2016

0.2.1

0.2.1.0

Set of classes and traits to handle tree hierarchy in Laravel Eloquent Models

  Sources   Download

The Requires

 

14/10 2016

0.2.0

0.2.0.0

Set of classes and traits to handle tree hierarchy in Laravel Eloquent Models

  Sources   Download

The Requires

 

14/10 2016

0.1.4

0.1.4.0

Set of classes and traits to handle tree hierarchy in Laravel Eloquent Models

  Sources   Download

The Requires

 

10/08 2016

0.1.3.1

0.1.3.1

Set of classes and traits to handle tree hierarchy in Laravel Eloquent Models

  Sources   Download

The Requires

 

23/05 2016

0.1.3

0.1.3.0

Set of classes and traits to handle tree hierarchy in Laravel Eloquent Models

  Sources   Download

The Requires

 

10/05 2016

0.1.2

0.1.2.0

Set of classes and traits to handle tree hierarchy in Laravel Eloquent Models

  Sources   Download

The Requires

 

10/09 2015

0.1.1

0.1.1.0

Set of classes and traits to handle tree hierarchy in Laravel Eloquent Models

  Sources   Download

The Requires

 

10/09 2015

0.1.0

0.1.0.0

Set of classes and traits to handle tree hierarchy in Laravel Eloquent Models

  Sources   Download

The Requires