In this new tutorial on the SitePoint PHP blog Francesco Malatesta introduces Ardent, an enhancement to the model system in the Laravel framework that allows for easy configuration of validation rules.
One of the (few) things I don't like about Laravel is that you cannot move the validation code from your controller to your models easily. When I write software I like to apply the "fat models, skinny controllers" principle. So, for me, writing the validation code in the controller is not a good thing. To solve this, I'd like to introduce Ardent, a great package for Laravel 4. To be more precise, Ardent presents itself as "Self-validating smart models for Laravel Framework 4's Eloquent ORM." In other words: exactly what we need!
He introduces the library as a part of a test application, a To-Do list that includes user and task handling. He starts with the creation of the base Laravel migrations to build the tables and the code for the two necessary models. He then shows how to install Ardent and put it to use in the controller code, adding validation rules and messages for each property on failure. He also shows how to use the model auto-hydration and hooks to make working with the models even easier. He finishes off the post showing how to set up relations "the Ardent way" using a slightly different format as the usual Laravel handling.
Link: http://www.sitepoint.com/ardent-laravel-models-steroids/
没有评论:
发表评论