Download the PHP package kingmaker/laravel-many-to-many-self-relationship without Composer

On this page you can find all versions of the php package kingmaker/laravel-many-to-many-self-relationship. 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-many-to-many-self-relationship

Laravel Many to Many Self Relationship

Version Packagist Downloads Laravel License

This package includes an extension to the belongsToMany Relationship of the Laravel allowing two-way association between the same model with a single Entry on the pivot table.

Installation

The package can be installed via Composer.

Version

This package is available on specific Laravel versions.

Package Version Laravel Version
1.x 6.20+ or 7.29+
2.0.x 8.17 - 8.34
2.1+ 8.35+ or 9+

Usage

Include the HasBelongsToManySelfRelation trait in the Model class and define the relation method as follows:

It is that simple and has all the Methods available on the belongsToMany(). The Related Posts can be accessed like any normal relation.

This is an extension over the native BelongsToMany class provided by the Eloquent.

Example

Consider there are 'posts' table and 'related_posts' table. The Post represent Post in the blog and it can have related posts similar to them.

The belongsToManySelf relation provides two-way association when calling the Relation.

Caution

There is a possibility for the returning of duplicate related object if the entities are related by 2rows on the Pivot table.

Use Cases

This two-way associated Many-to-Many relationship can be used in few peculiar situations. This relation doesn't suit all the Scenarios.

a) Related Posts / Products

Consider a blog or shopping website, where we have post / product related to each other. When the related Entity is matched via BelongsToMany relationship, the association of one Post/Product as related to the other post/product, on fetching the relatedPost or relatedProduct from the first Object will yield the second, but the inverse is not true (ie, getting first post/product as related post/product from the second)

b) Friend list in social media

In Social Media, the concept of Users being friended to one another can be easily achieved using this relation (not followers & following, just mutual friends). Once a Users add another User as friends, we can attach the User and doesn't need to care about the attachment of reverse while using this relationship.

Note: The Concept of followers and following has to use the Laravel's BelongsToMany relation. This relation is for friends like in Facebook.

c) Messages in a Chat

The Message in a Chat application, where a message is directed from a User to another User. This relation lets you retrieve all the Users that have messaged a particular User.

Note: There may be possibility of duplicates in this case

API Reference

The trait HasBelongsToManySelfRelation adds the method belongsToManySelf to your Model.

The BelongsToManySelf is a concrete/child/sub-class of the Eloquent BelongsToMany class. So, All the methods available on the BelongsToMany is also available on this Relation.

Known Issues

The following Issues / Problems were found in this package or the underlying Database Engine.

Tips

Contributing

Contributions are always welcome!

Feel free to open Issues and submit Pull Requests

You can also support me


All versions of laravel-many-to-many-self-relationship with dependencies

PHP Build Version
Package Version
Requires php Version ^7.2|^8.0
ext-json Version *
illuminate/database Version ~8.35|~9.0|~10.0|~11.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 kingmaker/laravel-many-to-many-self-relationship contains the following files

Loading the files please wait ....