Video wird geladen...

Video konnte nicht geladen werden

Zur Startseite

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

11,841 Aufrufe • vor 3 Jahren •via X (Twitter)

10 Kommentare

Profilbild von Brent
Brentvor 3 Jahren

What approach to request validation do you prefer?

Profilbild von Muhammed Sarı
Muhammed Sarıvor 3 Jahren

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

Profilbild von Doeke Norg
Doeke Norgvor 3 Jahren

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.

Profilbild von Nehal Hasnayeen 🛍
Nehal Hasnayeen 🛍vor 3 Jahren

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

Profilbild von Aidan Casey
Aidan Caseyvor 3 Jahren

Please don’t do anything other than attributes.

Profilbild von Gavin Courtney
Gavin Courtneyvor 3 Jahren

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

Profilbild von AJ Meireles
AJ Meirelesvor 3 Jahren

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.

Profilbild von mwm
mwmvor 3 Jahren

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.

Profilbild von Aɳԃɾҽყ
Aɳԃɾҽყvor 3 Jahren

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.

Profilbild von Gustavo Delgado
Gustavo Delgadovor 3 Jahren

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.

Ähnliche Videos