3

I have two arrays in my request:

from = ["Dec 24,2017",.....]
to   = ["Dec 21,2017",....]

And I have added rules in Laravel Validator for them

'from.*' => 'required',
'to.*' => 'required',

But now I have to add a new validation rule. The first element in "from" must be less than or equal to first element in "to", and respectively for other elements in the arrays.

from[0] <= to[0];
from[1] <= to[1];

Any help is appreciated.

1
  • why not just use a if loop to check each dates Commented Dec 27, 2017 at 14:06

1 Answer 1

2

You can use this snippet,

$date = ["Dec 24,2017", "Dec 24,2017","Dec 24,2017","Dec 24,2017"];
$date1 = ["Aug 24,2017", "Dec 26,2017","Feb 24,2017","Nov 24,2017"];

foreach($date as $k => $val){
    if(strtotime($date[$k]) > strtotime($date1[$k])){
        return false;
    }
}

and you can also write custom validation, and keep above code inside that.

It should solve your problem.

Sign up to request clarification or add additional context in comments.

1 Comment

Actually, there is no way to create a custom validation comparing two variables. The answer you provided is the best solution.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.