Not quite sure, if that will work, because I am beginner and I have not used them myself yet. Anyhow, the Laravel Validation doc states that you can use condtional "required" rules like "required_with", "required_without" etc. http://laravel.com/docs/4.2/validation
I would try something like this:
['field_a' => 'required_without:field_b', 'field_b' => 'required_without:field_a']
which should result in "field a must be present only, if field b is not present" and "field b must be present only, if field a is not".
It still leaves the possibility of filling both fields. Is that a problem for you?
goedda said:
Not quite sure, if that will work, because I am beginner and I have not used them myself yet. Anyhow, the Laravel Validation doc states that you can use condtional "required" rules like "required_with", "required_without" etc. http://laravel.com/docs/4.2/validation
I would try something like this:
['field_a' => 'required_without:field_b', 'field_b' => 'required_without:field_a']
which should result in "field a must be present only, if field b is not present" and "field b must be present only, if field a is not".
It still leaves the possibility of filling both fields. Is that a problem for you?
Thanks a bunch, it works perfectly! And the way my application works, choosing a and b is impossible since one is cleared when the other is selected.
Cheers!
Well, not to complicate things, but if it is not explicitly forbidden to post field a AND field b, respectively, then someone might use that to his/her advantage. You must ask yourself whether this might pose a problem, if your input contains data for field a and field b. If it does pose a problem, you should check for that too.
I guess, you could simply gather all data and delete either field a or b, if both contained data. That should not be a big problem.
goedda said:
Well, not to complicate things, but if it is not explicitly forbidden to post field a AND field b, respectively, then someone might use that to his/her advantage. You must ask yourself whether this might pose a problem, if your input contains data for field a and field b. If it does pose a problem, you should check for that too.
I guess, you could simply gather all data and delete either field a or b, if both contained data. That should not be a big problem.
Well, this is for an admin interface and the worst thing that happens is you get a working entry into the db, but it might not be the intended entry. So sure, if an admin wants to tamper, they can ruin things for themselves, but that's it :)
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community