v2.0 - fromRequest not working as intended (?) #173
-
First off, absolutely love the package, as someone who builds data intensive web application, I was really wondering how other people got through their array/object mess if there's a ton of data objects floating around. DTOs solve that, and this is a very big step up for anyone working with them, so many thanks! Second, I couldn't wrap my head around the magical conversion of injecting a DTO class into a controller method. According to the documentation, the creation of the DTO should be made based on the properties in the request, or, if defined, based on the fromRequest method of the DTO. What I experience, even with the "song title" example , is that the fromRequest is called, but the code first tries to populate it via request properties anyway. This leads to the fromRequest missing its goal (is it a bug or is this intentional?) because any additional properties you want to put into the constructor of your DTO via the fromRequest will need be defined as nullable in the constructor, since it first tries to make the DTO based on the request properties. So my question is, is this intended behaviour or is this a bug? If the latter, happy to help out! |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 11 replies
-
I think I need this feature. |
Beta Was this translation helpful? Give feedback.
-
I'm experiencing the same issue. I cannot get the fromRequest method to trigger when creating a DTO via injection into the controller. |
Beta Was this translation helpful? Give feedback.
-
Seems indeed like a bug but cannot replicate it. We have a test which tests this feature ( laravel-data/tests/RequestDataTest.php Lines 246 to 272 in 8a6a8af
Could you provide me a test where this feature isn't working? Then we can figure out what's going wrong. |
Beta Was this translation helpful? Give feedback.
Seems indeed like a bug but cannot replicate it. We have a test which tests this feature (
laravel-data/tests/RequestDataTest.php
Lines 246 to 272 in 8a6a8af