Download the PHP package ibrostudio/laravel-data-repository without Composer
On this page you can find all versions of the php package ibrostudio/laravel-data-repository. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download ibrostudio/laravel-data-repository
More information about ibrostudio/laravel-data-repository
Files in ibrostudio/laravel-data-repository
Package laravel-data-repository
Short Description This is my package laravel-data-repository
License MIT
Homepage https://github.com/ibrostudio/laravel-data-repository
Informations about the package laravel-data-repository
Laravel Data Objects Repository
Save Data Transfer Objects (from Spatie's Laravel Data) and Value Objects (from Michael Rubel's Laravel Value Objects) in database and attach to eloquent models.
Installation
Install the package via composer:
Then run the installer:
Usage
Add the trait IBroStudio\DataRepository\Concerns\HasDataRepository
to your Eloquent models.
The trait implements a MorphManyDataObjects
relationship that extends MorphMany
.
Working with DTO
Create your DTO following Spatie's Laravel Data documentation.
Working with Value Objects
Use built-in Value Objects or create one following Michael Rubel's Value Objects documentation.
Save the Value Object attached to the model in database:
For more complex usage, you can use Value Objects in DTO:
Creating or updating objects
The following method save the object in database and attach it to the model:
If an object with the sans data class is already attached to the model, its values will be replaced.
Unique data class
You can attach many objects to a model but only one for each data class by default. Considering the previous examples, the model can have only one SongData object (and other DTO or Value Objects).
Multiple data class
If you need more than one object from the same data class, use the valuesAttributes
parameter when you create or update an object:
Retrieving objects
You access to all MorphManyDataObjects
relations for a model with:
You can limit the instance to a specific data class to access a single object:
The object is then retrieved by the values()
method:
If necessary, you can also constrain the retrieval of the object to certain values of this object with the valuesQuery
parameter:
Eloquent attribute casting
You can get direct access to an object value like $model->song
instead of $model->data_repository(dataClass: SongData::class)
.
Add a unsignedBigInteger
column to your model:
And then add the cast to the model class:
Usage:
Built-in Objects Values
- ByteUnit
- EncryptableText
- GitSshUrl
- HashedPassword
- IpAddress
- SemanticVersion
- Timecode
- VersionedComposerJson
Testing
Changelog
Please see CHANGELOG for more information on what has changed recently.
License
The MIT License (MIT). Please see License File for more information.
All versions of laravel-data-repository with dependencies
darsyn/ip Version ^5.0
gabrielelana/byte-units Version ^0.5.0
illuminate/contracts Version ^11.0
michael-rubel/laravel-value-objects Version ^7.0
spatie/laravel-data Version ^4.0
spatie/laravel-package-tools Version ^1.14.0