Package for validations per service

Asked

Viewed 135 times

1

I’m developing a large project with Laravel and I need to validate my data. Initially I had thought to use Ardent, but this is not compatible/advisable for those who use the repository standard.

Which is why I’m going to have to do the validation for services. Advise some specific package?

  • 1

    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 the only requirement is to allow validation as services and not through models with Ardent.

1 answer

1

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.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.