DTO classes

A Data Transfer Object (DTO) is an object that is used to encapsulate data, and send it through different services. valravn has several dto classes which we are going to introduce them.

BatchUpdateDto

This class helps us to pass needed data to related batchUpdate method in service or repository classes. there is some example of how we should use it.

1BatchUpdateDto::make( [
2  'batch' => [
3    [ 'id' => 1 ], // make no change
4    [ 'id' => 3, 'the art' => "no limit i'm a fucking soldier" ],
5    [ 'id' => 5, 'the artist' => 'g-eazy' ],
6  ]
7] );

You just must pass the value of model's id, however other fillable attributes can be passed if there is a new value for them.

HasManyDto

This Dto class makes it easy to update a has many relationship. the usage should be like:

1HasManyDto::make( [
2  'related' => [
3    [ 'id' => 1 ],
4    [ 'id' => 3 ],
5    [ 'id' => 5 ],
6  ]
7] );

ManyToManyDto

ManyToManyDto uses to supply data for many-to-many relationships actions. this is how we should use it.

 1ManyToManyDto::make( [
 2  'related' => [
 3    [
 4      'id'    => 1,
 5      'pivot' => [
 6        'extra' => "same as it ever was, say it'll change but it never does",
 7        'song'  => 'farewell'
 8      ]
 9    ],
10    [ 'id' => 3 ],
11    [ 'id' => 5 ],
12    [
13      'id'    => 8,
14      'pivot' => [
15        'the art'    => "i'm talking to myself like every night, you could try to be a better guy",
16        'the artist' => 'g-eazy'
17      ]
18    ]
19  ]
20] );

MorphToDto

in the end, we have MorphToDto class that helps us to pass data to a morphTo relationship. there is an example:

1MorphToDto::make( [
2  'related' => [
3    'entity' => 'posts',
4  ]
5] );