Download the PHP package nevadskiy/laravel-many-to-morph without Composer
On this page you can find all versions of the php package nevadskiy/laravel-many-to-morph. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download nevadskiy/laravel-many-to-morph
More information about nevadskiy/laravel-many-to-morph
Files in nevadskiy/laravel-many-to-morph
Package laravel-many-to-morph
Short Description The missing polymorphic relationship for Eloquent.
License MIT
Informations about the package laravel-many-to-morph
The Many-To-Morph relationship for Eloquent
A package that simplifies and enhances Many-To-Many polymorphic relationships in Laravel's Eloquent ORM.
📚 Introduction
One common type of relationship in Laravel's Eloquent ORM is the Many-To-Many polymorphic relation. While it works well for most use cases, you might encounter certain challenges that require more elegant solutions, for example:
- When you have numerous related models, you need to define a separate relation for each type of model.
- It is hard to retrieve all related models at once.
This package introduces a new Many-To-Morph relationship, inspired by the Directus's Many-to-Any relation that handles these problems.
📝 Table of Contents
- Installation
- Documentation
- Configuring Relationship
- Retrieving Relationships
- Ordering Relationships
- Eager Loading Relationships
- Attaching Relationships
- Detaching Relationships
- License
🔌 Installation
Install the package via Composer:
📄 Documentation
Configuring Relationship
To configure this relationship, you need to use the HasManyToMorph
trait, which provides a manyToMorph
method for defining the relation as follows:
Retrieving Relationships
You can retrieve relationships as shown below:
Ordering Relationships
To order relationships, you can use the orderBy
method directly on the taggables
relation like so:
Eager Loading Relationships
Eager loading relationships can be done like this:
Attaching Relationships
You can attach relationships with the following code:
You can also attach a model with pivot attributes:
Detaching Relationships
To detach relationships, use the following code:
📜 License
This package is open-source and is released under the MIT License. Please refer to the LICENSE file for more information.