Laravel developers want to give users the best possible user feedback but maintaining data flow can be trying. As the app grows in size, excessive controller classes turn a majestic monolithic into piles of spaghetti code regrets. The framework does offers dozens of useful validation rules and form classes for simple use cases to cover most needs. Unfortunately the documentation on customizing new rules for business edge cases (and their error messages) is fairly sparse.

The problem with documenting such framework abilities is domain knowledge being strongly contextualized. A walk-through of an extended case study is required to showcase all the nuances of building an app, be it testing, database performance, or security concerns. Laravel’s biggest attraction is its documentation’s accessibility but sometimes devs just have to get their hands dirty.

For this post, I decided to showcase two custom validation rules (with tests) that cover business logic that’s not too obscure. Some framework trickery has to be wrenched into validation for the best possible error message so I’m going to introduce you to the DataAwareValidator trait.

Read the rest of this entry »