Download the PHP package fidum/laravel-eloquent-morph-to-one without Composer
On this page you can find all versions of the php package fidum/laravel-eloquent-morph-to-one. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download fidum/laravel-eloquent-morph-to-one
More information about fidum/laravel-eloquent-morph-to-one
Files in fidum/laravel-eloquent-morph-to-one
Package laravel-eloquent-morph-to-one
Short Description Adds MorphToOne relation to Laravel eloquent
License MIT
Homepage https://github.com/fidum/laravel-eloquent-morph-to-one
Informations about the package laravel-eloquent-morph-to-one
Adds MorphToOne relation to Laravel eloquent
:mega: Shoutout to Ankur Kumar who wrote the original code for this relation in their package Eloquent Relations. I created this package as I needed to make a few tweaks to suit my needs. :raised_hands:
Installation
You can install the package via composer:
Usage
The MorphToOne
relation is uses Laravel's MorphToMany under the hood. However, the difference is that it returns one model instead of a Collection
of models.
If there is no related model in the database it will return null
where MorphToMany
would return an empty Collection
.
Example:
Now you can access the relationship like:
Prefer using sync
instead of save
when updating your relation.
:x: DO NOT use save
it will follow morphToMany
behaviour and create rather than update existing.
Testing
Changelog
Please see CHANGELOG for more information on what has changed recently.
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
- Daniel Mason
- All Contributors
License
The MIT License (MIT). Please see License File for more information.
All versions of laravel-eloquent-morph-to-one with dependencies
illuminate/database Version ^10.0|^11.0|^12.0
illuminate/support Version ^10.0|^11.0|^12.0