New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[5.0] Array Input Validation #5645
Comments
👍 |
👍 |
Honestly, multi-dimensional array validation is a big ball ache in general. It would be nicer if Laravel could have some form of built in support for this but once you dig into it it's a pretty complicated thing to get right. I have built a custom package that did array validation like you have posted:
But it was abandoned because found it to make too much assumptions and became impossible to determine what input was validated exactly, allowing us to fill our models with just that validated input.
|
@garygreen I just understand what you try to tell me, and I think it seems like ok. I will try to use for Array Inputs, Thanks! |
Isn't this what $validator = Validator::make(Input::all(), [...]);
$validator->each('foo', [
'bar' => 'numeric',
]);
if ($validator->passes())
{
//
} |
Yeh, probably. |
@JosephSilber, actually it's not. I just try to arrive all childs with '*' operator. And each function can't help to me because of that validate function of FormRequest class wants to an array which have validator rules. Or I can re-write validate function on which extends FormRequest class, so I don't need to use validate function for that. |
@kalaomer The You can apply your own validator in the use Illuminate\Validation\Factory;
use Illuminate\Foundation\Http\FormRequest;
class MyFormRequest extends FormRequest {
public function validator(Factory $factory)
{
$validator = $factory->make($this->all(), [...]);
$validator->each('foo', [
'bar' => 'numeric',
]);
return $validator;
}
} It will then use this validator instead of creating its own from the |
Hi;
I was seen on 4.3 features and I like form validation so I try to use it. But I have a problem for validate to array inputs. That's like;
I have a method but it's not clean one. So I use rule templates that is like
foo.*.bar
. It means bar is child of foo's child. So I create true ways with this template and try to Validate inputs. It is run now but not clean, So any plan to easy way for this?The text was updated successfully, but these errors were encountered: