Closed eelco2k closed 3 months ago
This is quite logical, since you're resolving data from the container, the request is automatically validated based upon the data object. Only one key is provided so it fails on the second one.
In this case, create a new data object once your model isn saved.
Yes, silly me. Already figured it out. Thanks for the clarification though. ☺️
✏️ Describe the bug Find a record of a Model, use the ->fill() method for updating that model and then use the DTO for validating. The validateAndCreate($model) method only sees the $model = Model::find($id); initial data of the model and so returns validation errors of the not added fields in ->fill()
↪️ To Reproduce Simple TestModel with 2 fillable fields: 'title' and 'description'. Request is a POST request with an id param in route uri. postData is:
{ title: "updated title" }.
(so NO description)✅ Expected behavior As the $model is filled with new data but also has the original data from the model the validation failure of description should not occur. even when converting it to an Array (as in $modelArrNew) all the required fields are in the array.
Maybe i'm just doing something wrong here..
🖥️ Versions
Laravel: 10.48.14 Laravel Data: 4.7.0 PHP: 8.3.7