Загрузка видео...

Не удалось загрузить видео

На главную

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

11,841 просмотров • 3 лет назад •via X (Twitter)

Комментарии: 10

Фото профиля Brent
Brent3 лет назад

What approach to request validation do you prefer?

Фото профиля Muhammed Sarı
Muhammed Sarı3 лет назад

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

Фото профиля Doeke Norg
Doeke Norg3 лет назад

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 🛍
Nehal Hasnayeen 🛍3 лет назад

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
Aidan Casey3 лет назад

Please don’t do anything other than attributes.

Фото профиля Gavin Courtney
Gavin Courtney3 лет назад

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
AJ Meireles3 лет назад

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
mwm3 лет назад

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ɳԃɾҽყ
Aɳԃɾҽყ3 лет назад

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
Gustavo Delgado3 лет назад

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.

Похожие видео