vendredi 6 novembre 2015

Using Laravel mutators as validation when setting a value

Let's say I have an object with a field called cake. This cake object as a type field that is a varchar and must have the format cake-(any number). Could I then use a mutator to make sure that someone is not setting a string with the wrong format?

For example if another developer tries to do cake->type = c2; should I throw an error from my mutator or should this be done somewhere else?

Is this best practice or is there a better place to validate setters?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire