Download the PHP package staudenmeir/laravel-merged-relations without Composer

On this page you can find all versions of the php package staudenmeir/laravel-merged-relations. 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 laravel-merged-relations

Laravel Merged Relations

CI Code Coverage PHPStan Latest Stable Version Total Downloads License

This Laravel Eloquent extension allows merging multiple relationships using SQL views.
The relationships can target the same or different related models.

Supports Laravel 5.5+.

Installation

composer require staudenmeir/laravel-merged-relations:"^1.0"

Use this command if you are in PowerShell on Windows (e.g. in VS Code):

composer require staudenmeir/laravel-merged-relations:"^^^^1.0"

Versions

Laravel Package
11.x 1.9
10.x 1.6
9.x 1.5
8.x 1.4
7.x 1.3
6.x 1.2
5.8 1.1
5.5–5.7 1.0

Usage

Use Cases

Use the package to merge multiple polymorphic relationships:

Or use it to merge relationships with different depths:

Step 1: Creating Views

Before you can define the new relationship, you need to create the merge view in a migration:

By default, the view doesn't remove duplicates. Use createMergeViewWithoutDuplicates() to get unique results:

You can also replace an existing view:

The package includes staudenmeir/laravel-migration-views. You can use its methods to rename and drop views:

If you are using php artisan migrate:fresh, you can drop all views with --drop-views.

Step 2: Defining Relationships

With the view created, you can define the merged relationship.

Use the HasMergedRelationships trait in your model and provide the view name:

If all original relationships target the same related model, you can use mergedRelationWithModel(). This allows you to access local scopes and use methods like whereHas() or withCount():

You can use the merged relationship like any other relationship:

Pivot Table Data

You can retrieve additional pivot columns if your merge view consists of many-to-many relationships.

Add the desired pivot columns to all relationships:

Limitations

In the original relationships, it's currently not possible to limit the selected columns or apply withCount().

In the merged relationships, it's not possible to remove global scopes like SoftDeletes. They can only be removed in the original relationships.

Testing

If you use PHPUnit or a similar tool to run tests, add this property to your base test class to ensure that database views are dropped when the test database is cleaned up:

Contributing

Please see CODE OF CONDUCT for details.


All versions of laravel-merged-relations with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
illuminate/database Version ^11.0
staudenmeir/laravel-migration-views Version ^1.9.1
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 staudenmeir/laravel-merged-relations contains the following files

Loading the files please wait ....