Last active
January 31, 2018 16:24
-
-
Save juampi92/1193f0c0c7d12433d33891ae794f8bbd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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