Loading video...

Video Failed to Load

Go Home

Can someone send help?? Poll in the next tweet 👇

11,841 views • 2 years ago •via X (Twitter)

10 Comments

Brent's profile picture
Brent2 years ago

What approach to request validation do you prefer?

Muhammed Sarı's profile picture
Muhammed Sarı2 years ago

Validation should be nowhere near a model. Option 1 is a nice use of PHP attributes.

Doeke Norg's profile picture
Doeke Norg2 years ago

I would do validation on the model. Validation shouldn't go on a DTO which is what the request is. And in the end, the model is responsible for its invariants and business rules. Validation is a big part, because it enforces correct state of the model.

Nehal Hasnayeen 🛍's profile picture
Nehal Hasnayeen 🛍2 years ago

no.3, so that there can be no possibility of invalid data, also single source of truth and one place to check/modify

Aidan Casey's profile picture
Aidan Casey2 years ago

Please don’t do anything other than attributes.

Gavin Courtney's profile picture
Gavin Courtney2 years ago

If you went with #3, how would you detect and catch each different property that fails validation - wouldn’t you get a TypeError with the first invalid data and only be able to report that? I.e. you couldn’t report multiple invalid properties

AJ Meireles's profile picture
AJ Meireles2 years ago

If I were you, I would stop creating this framework 😂 Every time you move forward I see this and I start to think that a lot of what you're doing makes sense.

mwm's profile picture
mwm2 years ago

The third option limits you on a custom form request. Works very well for CRUD operations on AR Models. I would go for #1 and allow for #3 in the Model as well.

Aɳԃɾҽყ's profile picture
Aɳԃɾҽყ2 years ago

Is it the responsibility of entities or models to perform validation? Some may say yes, others may say no. Personally, I believe the model should handle data validation.

Gustavo Delgado's profile picture
Gustavo Delgado2 years ago

I would go with the first option, and keep specific endpoint logic/validations in the request. Moving that into the models would impact in more edge cases that you think. It's easier to just add a new endpoint with custom rules than refactoring a model used by other contexts.

Related Videos