Download the PHP package dandelionmood/laravel-relatable without Composer
On this page you can find all versions of the php package dandelionmood/laravel-relatable. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download dandelionmood/laravel-relatable
More information about dandelionmood/laravel-relatable
Files in dandelionmood/laravel-relatable
Package laravel-relatable
Short Description Trait to manage an Eloquent model's related content
License MIT
Homepage https://github.com/spatie/laravel-relatable
Informations about the package laravel-relatable
NOTE: This package is not registered on Packagist and is abandoned. It's only being use in a few internal projects at Spatie
Trait to Manage an Eloquent Model's Related Content
The laravel-relatable
package provides a HasRelatedContent
trait, which allows you to easily relate models to other models of any type.
Afterwards, you can retrieve the post's related content via the related
accessor.
Spatie is a webdesign agency based in Antwerp, Belgium. You'll find an overview of all our open source projects on our website.
Install
You can install the package via composer:
In order to publish the migrations and configuration file, you'll need to register the service provider:
If you want to specify a custom table name, you'll need to publish and edit the configuration file:
Publishing and running the migrations is mandatory:
Usage
After running the migrations, you can start using the package by adding the HasRelatedContent
trait to your models.
Adding and Removing Related Content
You can add related content to a model using the relate
function. relate
expects a model or an ID and type as parameters.
Removing related content happens with the unrelate
function, which expects the same parameters.
Synchronizing Related Content
Related content can be synced like Laravel's sync function for many-to-many relationships. The first parameter of syncRelated
should be a collection of Eloquent models or an array containing associated arrays with ID's and types.
By default, syncRelated
will detach all other related models. If you just want to add related content, set the detach
parameter to false.
Retrieving Related Content
The HasRelatetContent
trait provides an accessor for related
. Related content will be loaded and cached in memory the first time this function is called.
The related content can be manually reloaded via the loadRelated
method. This method will refill the related cache, and return the collection.
A hasRelated
helper function is also provided.
Changelog
Please see CHANGELOG for more information what has changed recently.
Testing
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
Credits
- Sebastian De Deyne
- All Contributors
About Spatie
Spatie is a webdesign agency based in Antwerp, Belgium. You'll find an overview of all our open source projects on our website.
License
The MIT License (MIT). Please see License File for more information.