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!
As you can imagine, it’s an extension of the Eloquent Model class, basically. This package comes with some new functionality, utilities and methods dedicated to input validation and other little things.
Our Test Application
For a better understanding of the advantages you can enjoy while using Ardent, we will set up a little test application. Nothing complicated: a simple To-Do List app.
Of course, I’m not going to implement a complete application: I just want to explain some principles, so I will make some controllers and models - no views. After that, I will “translate” the code using Ardent.
Our To-Do List will count two different entities:
User
- id
- first_name
- last_name
- password
Task
- id
- name
- status (done / not done)
A really basic project. However, if you don’t want to write code, don’t worry: I have already prepared a migration that you can use to generate the database. Use it!
Continue reading %Ardent: Laravel Models on Steroids%
more
{ 0 comments... » Ardent: Laravel Models on Steroids read them below or add one }
Post a Comment