I want to extend the form validation class to support array form elements, as described here for L3 to L4.
First, I changed the Validator alias with this to app/config/app.php:
'Validator' => 'app\lib\Support\Facades\Validator',
Then I saved these codes as app / lib / Support / Facades / Validator.php
<?php namespace app\lib\Support\Facades;
class Validator extends \Illuminate\Support\Facades\Validator {
public function __call($method, $parameters) {
if (substr($method, -6) === '_array') {
$method = substr($method, 0, -6);
$values = $parameters[1];
$success = true;
foreach ($values as $value) {
$parameters[1] = $value;
$rule = snake_case(substr($method, 8));
if (isset($this->extensions[$rule]))
{
$success &= $this->callExtension($rule, $parameters);
}
throw new \BadMethodCallException("Method [$method] does not exist.");
}
return $success;
} else {
return parent::__call($method, $parameters);
}
}
protected function getMessage($attribute, $rule) {
if (substr($rule, -6) === '_array') {
$rule = substr($rule, 0, -6);
}
return parent::getMessage($attribute, $rule);
}
}
Then I made sure that mine composer.jsonhas a folder included for startup:
"autoload": {
"classmap": [
"app/commands",
"app/controllers",
"app/models",
"app/database/migrations",
"app/database/seeds",
"app/tests/TestCase.php",
"app/lib",
"app/lib/Support",
"app/lib/Support/Facades"
]
},
Then I ran php composer.phar dump-autoloadto create startup classes.
The thing is, it doesn't seem to work. I even tried to add a special verification method to the file I created, something like this:
protected function validateTest($attribute, $value) {
return $value=='test';
}
It says: Method [validateTest] does not exist.. I changed the value protectedto public, anyway.
get_class(Validator::getFacadeRoot()) \Illuminate\Validation\Factory, , , : Non-static method Illuminate\Validation\Factory::make() should not be called statically.
. , , L4, , __call() getMessage().
, ?