Download the PHP package paxha/laravel-recursive-relationships without Composer
On this page you can find all versions of the php package paxha/laravel-recursive-relationships. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download paxha/laravel-recursive-relationships
More information about paxha/laravel-recursive-relationships
Files in paxha/laravel-recursive-relationships
Package laravel-recursive-relationships
Short Description This Laravel Eloquent extension provides recursive relationships using common table.
License MIT
Informations about the package laravel-recursive-relationships
Introduction
This Laravel Eloquent extension provides recursive relationships using common table.
Installation
composer require paxha/laravel-recursive-relationships
Usage
- Getting Started
- Relationships
- Scopes
- Functions
Getting Started
Consider the following table schema for hierarchical data:
Use the HasRecursiveRelationships
trait in your model to work with recursive relationships:
By default, the trait expects a parent key named parent_id
. You can customize it by overriding getParentKeyName()
:
Relationships
The trait provides various relationships:
children()
: The model's direct children.nestedChildren()
: The model's nested children.parent()
: The model's direct parent.nestedParents()
: The model's nested parents by object.
Scopes
The trait provides query scopes to filter models by their position in the tree:
hasChildren()
: Models with children.hasParent()
: Models with a parent.leaf()
: Models without children.root()
: Models without a parent.
Functions
The trait provides helper functions:
descendents()
: The model's all Children in single array.ancestors()
: The model's all parents in single array.siblings()
: The parent's other children.
License
This is open-sourced laravel library licensed under the MIT license.