Download the PHP package baril/bonsai without Composer

On this page you can find all versions of the php package baril/bonsai. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package bonsai

Bonsai :deciduous_tree:

Version License Downloads Tests Coverage

This package is an implementation of the "Closure Table" design pattern for Laravel Eloquent. This pattern allows for fast querying of tree-like structures stored in a relational database. It is an alternative to nested sets.

You can find the full API documentation here.

Version compatibility

Laravel Bonsai
13.x 3.5+
12.x 3.3+
11.x 3.2+
10.x 3.1+
9.x 3.x
8.x 2.x / 3.x
7.x 1.x
6.x 1.x

:warning: Up until version 3.2, only MySQL is supported. Starting with version 3.3, all DBMSs supported by Eloquent are supported by this package.

Setup

First, your main table needs a parent_id column (the name can be customized). This column is the one that holds the canonical data: the closures are merely a duplication of that information.

Then, your model must implement the Baril\Bonsai\Concerns\BelongsToTree trait.

You can use the following properties to specify the table and column names:

Once your model is ready, you have to run the bonsai:grow command (described below).

Artisan commands

bonsai:grow

The bonsai:grow command will generate the migration file to create the closure table for your model:

bonsai:fix

If your tag table already contains data, you have to run another command to create the closures for the existing data:

This command is also useful at any time if your closures get corrupt somehow, as it will truncate the closure table and fill it again based on the data found in the main table's parent_id column.

bonsai:show

The bonsai:show command provides a quick-and-easy way to output the content of the tree. It takes a label parameter that defines which column (or accessor) to use as label. Optionally you can also specify a max depth.

Updating the tree

Just fill the model's parent_id and save the model: the closure table will be updated accordingly.

The save method will throw a \Baril\Bonsai\TreeException in case of a redundancy error (i.e. if the parent_id corresponds to the model itself or one of its descendants).

You can also change the parent by using the graft and graftOnto methods:

The cut method turns the model into a root (with its descendants preserved):

When you delete a model, its closures will be deleted automatically. If the model has descendants, the delete method will throw a TreeException. If you want to delete the model and all its descendants, use the deleteTree method instead:

Relationships

The BelongsToTree trait provides the following relationships:

Siblings

:bulb: The siblings relation is a many-to-many relation, but under the hood, it extends HasMany.

The siblings relation has the following scopes:

Ancestors and descendants

:warning: The ancestors and descendants relations are read-only. Using the attach or detach methods on these relations will throw an exception.

The ancestors and descendants relations have the following scopes:

Loading or eager-loading the descendants relation will automatically load the children relation (with no additional query). Furthermore, it will load the children relation recursively for all the eager-loaded descendants:

Similarly, loading the ancestors relation will load the parent relation recursively.

Methods

The BelongsToTree trait provides the following methods:

Query scopes

The BelongsToTree trait provides the following query scopes:

Special trees

Soft deleting tree

To implement soft delete on your model, use the Baril\Bonsai\Concerns\SoftDeletes trait instead of Illuminate\Database\Eloquent\SoftDeletes:

The trait defines the forceDeleteTree method (which is similar to deleteTree for hard delete) and the restoreTree method. The latter method restores the model and all its soft-deleted descendants.

When you restore a model (either with restore or restoreTree), it will be restored under its original parent, assuming it still exists. If the parent has been deleted (either soft or hard) in the meantime, trying to restore the child will throw a TreeException. In this case, you may want to "graft" or "cut" the model before you restore it:

Ordered tree

If you need each level of your tree to be explicitly ordered, install the Orderly package in addition to Bonsai:

You will need a position column in your main table (the name of the column can be customized using the $orderColumn property).

Your model must use either the Baril\Bonsai\Concerns\Orderable trait or the Baril\Bonsai\Concerns\Ordered trait.

If you're using Orderable, you can order the children relation like this:

If you're using Ordered, the children relation is automatically ordered.

Check out the documentation of the Orderly package to see all available methods.

Changelog

Please see CHANGELOG for more information on what has changed recently.


All versions of bonsai with dependencies

PHP Build Version
Package Version
Requires illuminate/database Version ^8.0|^9.0|^10.0|^11.0|^12.0|^13.0
illuminate/support Version ^8.0|^9.0|^10.0|^11.0|^12.0|^13.0
illuminate/console Version ^8.0|^9.0|^10.0|^11.0|^12.0|^13.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package baril/bonsai contains the following files

Loading the files please wait ...