samedi 30 avril 2016

Validation Design Pattern in PHP's Laravel (Ruby on Rails)

I have serious problem with choosing validation design pattern form my mid-large level project. I know two that they are quite nice, but I don't feel about which to choose:

1 Validation inside model.

In L4.2 there was a bundle named: Ardent. He has few nice solutions. One of then was validation handle on before saving event. It was wery helpful especially for smaller project. Minus was that that validation logic was kept directly in model.

2 Validation from service,

Another good practice that I know i validation from service. It means that we create servic for models that is responsible for write acions (mainly also for some of the reads). We can mange here validating on before any save (create, update etc.). In my opinion is better then my first propositon. The minus is - we have to remeber to put all model's input data through the service. Otherwise we won't get validation and other things directly from service.

Which of these two? Or maybe someone have something better, more clever? :)

Aucun commentaire:

Enregistrer un commentaire