Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

SitePoint PHP Blog:
Ardent: Laravel Models on Steroids
Sep 19, 2014 @ 16:54:34

In 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.

tagged: laravel model ardent library tutorial introduction

Link: http://www.sitepoint.com/ardent-laravel-models-steroids/


Trending Topics: