Implementing validation as a service:
I don’t know a package, I suspect it doesn’t exist yet.
But there are a couple of articles that contain exactly what you want:
http://culttt.com/2013/07/29/creating-laravel-4-validation-services/
http://culttt.com/2014/01/13/advanced-validation-service-laravel-4/
With the solution presented, you specify your validation rules like this:
<?php namespace App\Service\Validation\Laravel;
use App\Service\Validation\ValidableInterface;
class UserCreateValidator extends LaravelValidator implements ValidableInterface {
/**
* Validação para criar um novo User
*
* @var array
*/
protected $rules = array(
'username' => 'required|min:2',
'email' => 'required|email',
'password' => 'required'
);
}
The class UserCreateValidator
inherits basic class functionality AbstractValidator
, Laravel’s specific functionality to run class validation tests LaravelValidator
and finally each daughter class finalizes the implementation with the specifically required rules. The implementation of ValidableInterface
ensures that the class meets the requirements of the contract.
Welcome, Miguel. Do you have more specific requirements? Asking what others advise does not work well here, because each will give his or her opinion and it will be difficult to choose one as correct. I suggest you read We must accept questions of recommendation and Good subjective, bad subjective.
– bfavaretto
@bfavaretto the only requirement is to allow validation as services and not through models with Ardent.
– Miguel Borges