Replies: 1 comment
-
In this case I would just use the Arr::flatten helper in Laravel. You could extend from the base data object and even add a method like toFlattenArray and then extend from that class. Not something for in the package but certainly something which might be useful in your project. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello
I am in charge of a huge projects with hundreds of classic Laravel requests forms and I would like to convert them to DTOs.
One problem we are facing is nested DTOs.
For example, we have this request input already in place:
In our database, all these fields are in a single table.
So we start by making our DTO where we define stuff like this (pardon me, I am on my phone in bed!)
That extra DTO has the timezone and another DTO for the frontend settings.
Now, when we inject the DTO in the controller and the data is validated, all is well except one thing. When we do for example: $request->toArray(), we get a nested array instead of a flatten array like our table structure. This is expected, I know.
But how should we handle this situation to make it work? Is there an attribute that we can define that says merge this child DTO with the parent DTO ? Did we miss something? Should we flatten the array outside of the DTO with helpers? Any ideas?
Thanks you
Beta Was this translation helpful? Give feedback.
All reactions