Implementing validation as a service:
I do not know a package, I suspect it does not yet exist.
But there are a couple of articles that contain exactly what you want:
link
link
With the solution presented, you specify your validation rules as follows:
<?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 UserCreateValidator
class inherits the basic functionality of the AbstractValidator
class, the Laravel-specific functionality to run validation tests of the LaravelValidator
class, and finally each child class completes the implementation with the specifically required rules. The implementation of ValidableInterface
ensures that the class meets the contract requirements.