Download the PHP package musoftware/eloquent-has-many-deep without Composer

On this page you can find all versions of the php package musoftware/eloquent-has-many-deep. 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 eloquent-has-many-deep

CI Code Coverage Scrutinizer Code Quality Latest Stable Version Total Downloads License

Introduction

This extended version of HasManyThrough allows relationships with unlimited intermediate models.
It supports polymorphic relationships and all their possible combinations.

Supports Laravel 5.5.29+.

Installation

composer require staudenmeir/eloquent-has-many-deep:"^1.7"

Versions

Laravel Package
5.5–5.7 1.7
5.8 1.8
6.x 1.11
7.x 1.12
8.x 1.13

Usage

The package offers two ways of defining deep relationships:
You can specify the intermediate models, foreign and local keys manually or concatenate existing relationships.

HasMany

Consider the documentation example with an additional level:
Country → has many → User → has many → Post → has many → Comment

Just like with hasManyThrough(), the first argument of hasManyDeep() is the related model. The second argument is an array of intermediate models, from the far parent (the model where the relationship is defined) to the related model.

By default, hasManyDeep() uses the Eloquent conventions for foreign and local keys. You can also specify custom foreign keys as the third argument and custom local keys as the fourth argument:

You can use null placeholders for default keys:

ManyToMany

You can include ManyToMany relationships in the intermediate path.

ManyToMany → HasMany

Consider the documentation example with an additional HasMany level:
User → many to many → Role → has many → Permission

Add the pivot table to the intermediate models:

If you specify custom keys, remember to swap the foreign and local key on the "right" side of the pivot table:

ManyToMany → ManyToMany

Consider the documentation example with an additional ManyToMany level:
User → many to many → Role → many to many → Permission

Add the pivot table to the intermediate models:

MorphMany

You can include MorphMany relationships in the intermediate path.

Consider the documentation example with an additional level:
User → has many → Post → morph many → Comment

Specify the polymorphic foreign keys as an array, starting with the *_type column:

MorphToMany

You can include MorphToMany relationships in the intermediate path.

Consider the documentation example with an additional level:
User → has many → Post → morph to many → Tag

Add the pivot table to the intermediate models and specify the polymorphic foreign keys as an array, starting with the *_type column:

Remember to swap the foreign and local key on the "right" side of the pivot table:

MorphedByMany

You can include MorphedByMany relationships in the intermediate path.

Consider the documentation example with an additional level:
Tag → morphed by many → Post → has many → Comment

Add the pivot table to the intermediate models and specify the polymorphic local keys as an array, starting with the *_type column:

BelongsTo

You can include BelongsTo relationships in the intermediate path:
Tag → morphed by many → Post → belongs to → User

Swap the foreign and local key:

Existing Relationships

You can also define a HasManyDeep relationship by concatenating existing relationships:

HasOneDeep

Define a HasOneDeep relationship if you only want to retrieve a single related instance:

Intermediate and Pivot Data

Use withIntermediate() to retrieve attributes from intermediate tables:

By default, this will retrieve all the table's columns. Be aware that this executes a separate query to get the list of columns.

You can specify the selected columns as the second argument:

As the third argument, you can specify a custom accessor:

If you retrieve data from multiple tables, you can use nested accessors:

Use withPivot() for the pivot tables of BelongsToMany and MorphToMany/MorphedByMany relationships:

You can specify a custom pivot model as the third argument and a custom accessor as the fourth:

Table Aliases

If your relationship path contains the same model multiple times, you can specify a table alias:

Use the HasTableAlias trait in the models you are aliasing:

For pivot tables, this requires custom models:

Use setAlias() to specify a table alias when concatenating existing relationships (Laravel 6+):

Soft Deleting

By default, soft-deleted intermediate models will be excluded from the result. Use withTrashed() to include them:

Contributing

Please see CODE OF CONDUCT for details.


All versions of eloquent-has-many-deep with dependencies

PHP Build Version
Package Version
Requires php Version ^7.3|^8.0
illuminate/database Version ^8.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 musoftware/eloquent-has-many-deep contains the following files

Loading the files please wait ....