0

I have a class which checks two dates and sees if the value is greater than or equal to the second parameter. My question is - how do you properly get the value from the second field I've used Input::get($value_to_compare) which I don't think is actually the correct way to go about it.

class CoreValidator extends Illuminate\Validation\Validator {

protected function validateDateLessThanOrEqualTo($attribute, $value, $parameters)
{

    /*
     * If a input with the name equal to the value we compare with, we
     * use it, otherwise we proceed as usual
     */

    if( isset( $this->attributes[ $parameters[0] ] ) )
    {

      $value_to_compare = $this->attributes[ $parameters[0] ];

    }//if we have an input with this name
    else
    {

        $value_to_compare = $parameters[0];

    }//we compare with the provided value



    return ( date_parse( $value ) <= date_parse( Input::get($value_to_compare) ) );

}   

protected function replaceDateLessThanOrEqualTo($message, $attribute, $rule, $parameters)
{


    return str_replace(':other', ucwords(str_replace('_', ' ', $parameters[0])), $message);

}
}

1 Answer 1

1

You can use the member variable $data on the validator object to get the other attributes's value:

return ( date_parse( $value ) <= date_parse( $this->data[$value_to_compare] ) );
Sign up to request clarification or add additional context in comments.

Comments

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.