Video yükleniyor...

Video Yüklenemedi

Ana Sayfaya Dön

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

11,841 görüntüleme • 3 yıl önce •via X (Twitter)

10 Yorum

Brent profil fotoğrafı
Brent3 yıl önce

What approach to request validation do you prefer?

Muhammed Sarı profil fotoğrafı
Muhammed Sarı3 yıl önce

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

Doeke Norg profil fotoğrafı
Doeke Norg3 yıl önce

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 🛍 profil fotoğrafı
Nehal Hasnayeen 🛍3 yıl önce

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 profil fotoğrafı
Aidan Casey3 yıl önce

Please don’t do anything other than attributes.

Gavin Courtney profil fotoğrafı
Gavin Courtney3 yıl önce

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 profil fotoğrafı
AJ Meireles3 yıl önce

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 profil fotoğrafı
mwm3 yıl önce

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ɳԃɾҽყ profil fotoğrafı
Aɳԃɾҽყ3 yıl önce

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 profil fotoğrafı
Gustavo Delgado3 yıl önce

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.

Benzer Videolar