Replies: 1 comment
-
From won't do validation by default, validateAndCreate will which means the DataCollection is passed to the Laravel validator which doesn't know a DataCollection is an array basically. In v4 we'll fase out DataCollections in favor for arrays and collections which should fix this problem.
You can do this by changing the validation Pipe to always validate everything passed to it.
The quick start guide needs an update, anyone is welcome PR'ing one. I don't think we need to mention that you can pas an array nested, these things should just work. But you're always welcome to send in a PR updating the docs. |
Beta Was this translation helpful? Give feedback.
-
Why does validation fail for this one?
So:
from()
works with array and DataCollection, butvalidateAndCreate()
only works with array.getValidationRules
indeed shows:But that logic / the flow is unclear to me. I specify
$songs
will be aDataCollection
, I would then expect that the validator knows theDataCollection
has an array "inside".In general I find my self confused often about the difference between
validateAndCreate
andfrom
.I usually do want to validate the data (from array, not request), but after mapping/casting/etc, not before.
BTW it would be really helpful to bring the documentation pages more together / in sync. E.g. the quick guide mentions passing a regular array as nested collection using
from
, but the detailed collections page does not.Beta Was this translation helpful? Give feedback.
All reactions