Download the PHP package allcaretravel/laravel-relatable without Composer
On this page you can find all versions of the php package allcaretravel/laravel-relatable. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download allcaretravel/laravel-relatable
More information about allcaretravel/laravel-relatable
Files in allcaretravel/laravel-relatable
Package laravel-relatable
Short Description Trait to manage an Eloquent model's related content
License MIT
Homepage https://github.com/allcaretravel/laravel-relatable
Informations about the package laravel-relatable
NOTE: This project is forked from spatie/laravel-relatable
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.
Support us
We invest a lot of resources into creating best in class open source packages. You can support us by buying one of our paid products.
We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on our contact page. We publish all received postcards on our virtual postcard wall.
Install
You can install the package via composer:
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
- Sophy SEM
- 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.