grixu/relationship-data-transfer-object

This package is abandoned and no longer maintained. No replacement package was suggested.

Simple class for wrapping data with relationships. But without those meta-data when dump DTO to Array

Maintainers

Package info

github.com/grixu/relationship-data-transfer-object

pkg:composer/grixu/relationship-data-transfer-object

Statistics

Installs: 663

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

2.0.0 2021-04-30 13:21 UTC

This package is auto-updated.

Last update: 2021-11-30 14:32:39 UTC


README

Latest Version on Packagist

Simple class for wrapping data with relationships. But without those meta-data when dump DTO to Array

Installation

You can install the package via composer:

composer require grixu/relationship-data-transfer-object

Usage

class YourDto extends RelationshipDataTransferObject
{
    // go forward as with normal DTO from spatie/data-transfer-object
    public string $some;
}

// Let's create one DTO object
$dto = new YourDto([
    'some' => 'data',
    'relationships' => [
        [
            'localModel' => Model::class,
            'foreignModel' => ForeignModel::class,
            'localKey' => 'fk',
            'foreignKey' => 'id',
            'type' => BelongsTo::class,
            'pivot' => [
                'field' => 'extra data'
            ]
        ],
        ...
    ]);

// When you dump DTO to aaray it wouldn't contain relationships field
$dto->toArray();

// But you can still access those data
$dto->relationships;

Testing

composer test

Changelog

Please see CHANGELOG for more information 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

License

The MIT License (MIT). Please see License File for more information.