I'd like to add multiple custom validation, each as their own file.
So far, I've modified my app/start/global.php file to
global.php
ClassLoader::addDirectories(array(
app_path().'/commands',
app_path().'/controllers',
app_path().'/models',
app_path().'/database/seeds',
app_path().'/validators' // <--- Added this folder
));
// Only the first resolver works.
// I cannot seem to have multiple of these files
Validator::resolver(function($translator, $data, $rules, $messages)
{
return new ScheduleValidator($translator, $data, $rules, $messages);
});
Validator::resolver(function($translator, $data, $rules, $messages)
{
return new UserValidator($translator, $data, $rules, $messages);
});
And each of my validation files would be in the /validators as
ScheduleValidator.php
class ScheduleValidator extends Illuminate\Validation\Validator
{
protected $implicitRules = array('Required', 'RequiredWith', 'RequiredWithout', 'RequiredIf', 'Accepted', 'RequiredWithoutField');
public function __construct(\Symfony\Component\Translation\TranslatorInterface $translator, $data, $rules, $messages = array())
{
parent::__construct($translator, $data, $rules, $messages);
$this->isImplicit('fail');
}
/**
* Validates type to be of the type 'common', 'template', or 'revision'
*/
public function validateTypeSchedule($attribute, $value, $parameters = null)
{
$valid_types = ['template', 'common', 'revision'];
return in_array($value, $valid_types);
}
// and the other validators ...
}
So how can I add multiple of these validators?