Skip to content

Instantly share code, notes, and snippets.

@juampi92
Last active January 31, 2018 16:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save juampi92/1193f0c0c7d12433d33891ae794f8bbd to your computer and use it in GitHub Desktop.
Save juampi92/1193f0c0c7d12433d33891ae794f8bbd to your computer and use it in GitHub Desktop.
<?php
namespace App\Rules;
use Illuminate\Support\Facades\Validator;
use Illuminate\Contracts\Validation\Rule;
class BaseRule
{
protected $validator = null;
/**
* @param mixed $value
* @param array|string|Rule $rules
* @param string $name Name of the property (optional)
*
* @return boolean
*/
protected function validate($value, $rules, $name = 'variable')
{
if (!is_string($rules) && !is_array($rules)) {
$rules = [$rules];
}
$this->validator = Validator::make([$name => $value], [$name => $rules]);
return $this->validator->passes();
}
/**
* @return null|Validator
*/
protected function getValidator()
{
return $this->validator;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment