All notable changes to this project will be documented in this file.
The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.
- Command
make:dto
now opens the file after is generated
extended-php
dependency replaced withextended-laravel
(required to useOpensGeneratedFiles
trait on themake:dto
command)
- New dependency name replaced
laravel-helpers
withextended-php
- Filtering reset keys to numeric when string needed
- Filtering on collections with not null data
- Filtering on collections with not null data
- Improve model morph mapping sending multiple IDs and their matches types. Documentation link
- DataTransferObjects now have
dump
anddd
methods
toArray
method not returning everything when DTOs where used on the request and later on reused. Caveat: Only one DTO per request until v4 refactor
- Laravel 11 support
- Collected data transfer objects now mapped properly using
fromArray
- From request context with DTO's
filled
method not working properly
- Route resolution on the model's logic (
resolveRouteBindingQuery
)
- Route binding when nested DTO is being used with same parameter key as route binding
- Models route binding now uses Eloquent's Model
resolveRouteBindingQuery
method - Models uses default routing key (
getRouteKeyName
) only whenBindModel
PHP attribute doesn't have the using argument
- Routes binding models through DTOs now are injected back to route parameters (to be reused in every other part of the software)
BackedEnum
typed properties with union types falling back to original value
- laravel-helpers package version constraints so it doesn't conflict with any other package that uses it in the same way (or even the root project)
- Serialisation using old
BindModelUsing
instead of newBindModel
attribute
- JSON strings to collections (arrays or Illuminate's Collection instances)
- Regression introduced by morphs fix using abstract
Model
class
- Morph binding using generic Illuminate's model class (not instantiable), fallbacks to
Relation::morphMap
- Passing through with no type casting already matching typed properties (enums, objects, etc...)
- Morph support for data transfer objects model properties and collection properties. For e.g:
public Film|Post $taggable, public string $taggableType
- Simplificated
OpenSoutheners\LaravelDto\Attributes\BindModel
attribute grouping all the model binding options. - Support for
OpenSoutheners\LaravelDto\Attributes\BindModel
attribute in morph properties, which can be also used to customise the type key name. For e.g. from the same example from above:
#[BindModel(
using: [Post::class => 'slug'],
with: [Post::class => 'tags', Film::class => ['tags', 'posts']],
morphTypeKey: 'tagType'
)]
public Film|Post $taggable,
public string $tagType
- Replace all
#[BindModelUsing('attribute')]
to#[BindModel(using: 'attribute')]
in your code (take in mind it must not be repeated under the same property) - Replace all
#[BindModelWith(['relation1', 'relation2'])]
to#[BindModel(with: ['relation1', 'relation2'])]
in your code (take in mind it must not be repeated under the same property)
- Enums parsing when one is being passed to DTOs (thanks @coclav 🎉) [#6]
OpenSoutheners\LaravelDto\Attributes\WithDefaultValue
attribute to set default value#[WithDefaultValue(Authenticatable::class)]
will set as default value the authenticated user (Auth::user()
)
- Now
\stdClass
properties get properly serialised as multidimensional arrays
- TypeScript
.d.ts
generation command with--declarations
option
- Default TypeScript types generation command options now have some of them on the config file
- Config file now is exposed to be published using
vendor:publish --provider="OpenSoutheners\\LaravelDto\\ServiceProvider"
orvendor:publish --tag="config"
commands - Non typed properties when nullable or not while TypeScript types generation
- Keys normalisation on types generator (snake case when enabled from config)
- Types generator when empty collections
- Serialisation for DTO objects so now they can be sent to queued jobs
dto:typescript
command for generating TypeScript types based on your application's DTOs
- Sending multiple values (for e.g. 1,2,5) on a collection with
BindModelUsing
attribute or custom model'sgetRouteKeyName
method now works querying all models make:dto
command now does not generate aValidatedDataTransferObject
with request static method on it
- Request option for
make:dto
command when sent without a value fails
make:dto
with_id
ending properties
- Fix
make:dto
command when validated form request sent with properties that has children items likearray.*.item
DataTransferObject::toArray
when DTO constructedfromArray
is getting request stuff, it doesn't get all properties
make:dto
with request option doesn’t add class string to static method
make:dto
command with validated requests sent to option
- Validation not applied for ValidatedDataTransferObject interface DTOs
ValidatedDataTransferObject
interface is no longer resolved, insteadDataTransferObject
class will be the one resolved (for those DTOs that doesn't have aFormRequest
class on them, validated form data)
- Better error reporting when DTO class is being bound to a controller
- Collections does not get mapped when Illuminate's collection has been sent to DTO
- Model binding defaults to primary key instead of
Model::getRouteKeyName()
(which should be used for those coming from routes instead) - Route bound models are using specified attributes instead of default to IDs (model's primary keys). For e.g.
posts/{post:slug}
will use slug on the DTO query
- BindModelUsing now uses the attribute on the binding query
OpenSoutheners\LaravelDto\Attributes\BindModelUsing
property PHP attribute class for use attribute to do the binding/serialisation
- Issue mapping custom objects from data collections (native arrays or Illuminate's collections)
make:dto --request
command now accepts empty request option to create empty base DTO class with empty request method
make:dto --request
now fill request method properly
- Collections binding models were returning model instance instead of array or
Illuminate\Support\Collection
with the models inside DataTransferObject::filled()
method now checks within route parameters as well as sent request body data if is within request contextDataTransferObject::toArray()
method now returns arrays with nestedtoArray
calls when collections or models
php artisan make:dto --request='App\Http\Requests\PostCreateFormRequest' PostCreateData
will now fill the request part and all properties for you with their types (experimental)- Map arrays or json strings into generic objects (
\stdClass
) or custom objects (using their classes) - Map string dates into
Illuminate\Support\Carbon
orCarbon\Carbon
orCarbon\CarbonImmutable
instances
- Laravel collections not being mapped properly
- Arrays not mapping properly when not containing strings (arrays with arrays inside)
- Command option
--request
to createValidatedDataTransferObject
with request method in it.
- Add binding resolution so DataTransferObjects can act as validated requests using
ValidatedDataTransferObject
interface - Add authenticated user “automagical” binding to
DataTransferObject
property when possible (need to be typed as Authenticatable illuminate's contract)
- Now route parameters are merged into DataTransferObjects when running within requests context
- Minor issue, now doesn't query when sending model instance using
DataTransferObject::fromArray()
method
- Properties returned from
toArray
are now snake cased (frommyPropertyName
tomy_property_name
) - Improved
toArray
to return just some modified properties (from defaults)
toArray
method to DTOs
BindModelWith
attribute on collection typed properties
- Introducing mapped types using docblock
@param
type like the following:@param array<\App\Models\MyModel> $models
or@param \Illuminate\Support\Collection<\App\Models\MyModel> $models
- Optional normalisation option for properties names (
workspace_id
toworkspace
,post_tags
topostTags
, etc) to package config file (publish using commandphp artisan vendor:publish --provider="OpenSoutheners\LaravelDto\ServiceProvider"
) - Attribute
OpenSoutheners\LaravelDto\Attributes\NormaliseProperties
to use in some DTO classes that needs properties normalisation (when globally disabled from config) - Attribute
OpenSoutheners\LaravelDto\Attributes\BindModelWith
to bind to model with relationships included
- Now using
symfony/property-info
for better property assertion (so many bugs and inconsistencies on promoted properties in PHP8+ assertions)
DataTransferObject::fromArray
now usesinitialize
method instead ofwithDefaults
(internal change, shouldn't affect anything)
DataTransferObject::filled
method refactored with better logic
DataTransferObject::fromRequest()
method shortcut (does same asDataTransferObject::fromArray($request->validated())
orDataTransferObject::fromArray($request->all())
)
make:dto
command to generate data transfer object classes
- Initial release!