Build the error message for validation failures.

@param  string $message
@param  string $attribute
@param  string $rule
@param  array $parameters
@return string
184068
public function replaceImageSize($message, $attribute, $rule, $parameters)
    {
        $width = $height = $this->checkDimension($parameters[0]);
        if (isset($parameters[1])) {
            $height = $this->checkDimension($parameters[1]);
        }

        return str_replace(
            [':width', ':height'],
            [$width['message'], $height['message']],
            $message
        );
    }
134441
protected function validate($attribute, $rule)
	{
		list($rule, $parameters) = $this->parseRule($rule);

		if ($rule == '') return;

		// We will get the value for the given attribute from the array of data and then
		// verify that the attribute is indeed validatable. Unless the rule implies
		// that the attribute is required, rules are not run for missing values.
		$value = $this->getValue($attribute);

		$validatable = $this->isValidatable($rule, $attribute, $value);

		$method = "validate{$rule}";

		if ($validatable && ! $this->$method($attribute, $value, $parameters, $this))
		{
			$this->addFailure($attribute, $rule, $parameters);
		}
	}
104287
protected function validateAttribute( $rule, $attribute )
	{
		list( $rule, $parameters ) = $this->parseRule( $rule );

		if( $rule == '' )return;

		$method = "validate{$rule}";

		if( !method_exists( $this, $method )) {
			throw new BadMethodCallException( "Method [$method] does not exist." );
		}

		if( !$this->$method( $this->getValue( $attribute ), $attribute, $parameters )) {
			$this->addFailure( $attribute, $rule, $parameters );
		}
	}
1294049
public function validateIn($attribute, $value, $parameters)
    {
        if (is_array($value) && $this->hasRule($attribute, 'Array')) {
            foreach ($value as $element) {
                if (is_array($element)) {
                    return false;
                }
            }

            return count(array_diff($value, $parameters)) === 0;
        }

        return ! is_array($value) && in_array((string) $value, $parameters);
    }
704136
public function validateDistinct($attribute, $value, $parameters)
    {
        $data = Arr::except($this->getDistinctValues($attribute), $attribute);

        if (in_array('ignore_case', $parameters)) {
            return empty(preg_grep('/^'.preg_quote($value, '/').'$/iu', $data));
        }

        return ! in_array($value, array_values($data));
    }
1064148
protected function replaceDifferent($message, $attribute, $rule, $parameters)
	{
		return str_replace(':other', $this->getAttribute($parameters[0]), $message);
	}
888667
protected function getSizeMessage($attribute, $rule)
    {
        $lowerRule = snake_case($rule);

        // There are three different types of size validations. The attribute may be
        // either a number, file, or string so we will check a few things to know
        // which type of value it is and return the correct line for that type.
        $type = $this->getAttributeType($attribute);

        $key = "validation.{$lowerRule}.{$type}";

        return $this->translator->trans($key);
    }
414728
protected function validateIban($attribute, $value, $parameters)
    {
        // Since IBAN's has different lengths depending on which country
        // the IBAN it comes from. We unfortunately needs this rather ugly
        // array with country codes and a value which corrosponds to the length
        // of the IBAN in that given country
        $countryIbanLengths = [
            'AL' => 28, 'AD' => 24, 'AT' => 20, 'AZ' => 28, 'BH' => 22, 'BE' => 16, 'BA' => 20, 'BR' => 29,
            'BG' => 22, 'CR' => 21, 'HR' => 21, 'CY' => 28, 'CZ' => 24, 'DK' => 18, 'DO' => 28, 'TL' => 23,
            'EE' => 20, 'FO' => 18, 'FI' => 18, 'FR' => 27, 'GE' => 22, 'DE' => 22, 'GI' => 23, 'GR' => 27,
            'GL' => 18, 'GT' => 28, 'HU' => 28, 'IS' => 26, 'IE' => 22, 'IL' => 23, 'IT' => 27, 'JO' => 30,
            'KZ' => 20, 'XK' => 20, 'KW' => 30, 'LV' => 21, 'LB' => 28, 'LI' => 21, 'LT' => 20, 'LU' => 20,
            'MK' => 19, 'MT' => 31, 'MR' => 27, 'MU' => 30, 'MC' => 27, 'MD' => 24, 'ME' => 22, 'NL' => 18,
            'NO' => 15, 'PK' => 24, 'PS' => 29, 'PL' => 28, 'PT' => 25, 'QA' => 29, 'RO' => 24, 'SM' => 27,
            'SA' => 24, 'RS' => 22, 'SK' => 24, 'SI' => 19, 'ES' => 24, 'SE' => 24, 'CH' => 21, 'TN' => 24,
            'TR' => 26, 'AE' => 23, 'GB' => 22, 'VG' => 24, 'DZ' => 24, 'AO' => 25, 'BJ' => 28, 'BF' => 27,
            'BI' => 16, 'CM' => 27, 'CV' => 25, 'IR' => 26, 'CI' => 28, 'MG' => 27, 'ML' => 28, 'MZ' => 25,
            'SN' => 28, 'UA' => 29,
        ];

        // Prepare string for validation
        $value = str_replace(' ', '', strtoupper($value));

        // Grab country of IBAN
        $countryCode = substr($value, 0, 2);

        // Retrieve IBAN length
        $countryIbanLength = ! empty($countryIbanLengths[$countryCode]) ? $countryIbanLengths[$countryCode] : 0;

        // Validate IBAN length
        if ($countryIbanLength == 0 || strlen($value) != $countryIbanLength) {
            return false;
        }

        // Generate data for later checksum calculation
        $checksumData = [];
        foreach (range('A', 'Z') as $letter) {
            $checksumData[$letter] = strval($letter);
        }

        // Prepare for generation of checksum
        $value = substr($value, 4).substr($value, 0, 4);
        $value = str_replace(array_keys($checksumData), array_values($checksumData), $value);

        // Generate checksum
        $checksum = intval($value[0]);
        for ($i = 1; $i < strlen($value); $i++) {
            $checksum *= 10;
            $checksum += intval($value[$i]);
            $checksum %= 97;
        }

        // Verify checksum
        return $checksum == 1;
    }
1120122
protected function validateAttribute($attribute, $rule)
    {
        $this->currentRule = $rule;

        [$rule, $parameters] = ValidationRuleParser::parse($rule);

        if ($rule == '') {
            return;
        }

        // First we will get the correct keys for the given attribute in case the field is nested in
        // an array. Then we determine if the given rule accepts other field names as parameters.
        // If so, we will replace any asterisks found in the parameters with the correct keys.
        if (($keys = $this->getExplicitKeys($attribute)) &&
            $this->dependsOnOtherFields($rule)) {
            $parameters = $this->replaceAsterisksInParameters($parameters, $keys);
        }

        $value = $this->getValue($attribute);

        // If the attribute is a file, we will verify that the file upload was actually successful
        // and if it wasn't we will add a failure for the attribute. Files may not successfully
        // upload if they are too large based on PHP's settings so we will bail in this case.
        if ($value instanceof UploadedFile && ! $value->isValid() &&
            $this->hasRule($attribute, array_merge($this->fileRules, $this->implicitRules))
        ) {
            return $this->addFailure($attribute, 'uploaded', []);
        }

        // If we have made it this far we will make sure the attribute is validatable and if it is
        // we will call the validation method with the attribute. If a method returns false the
        // attribute is invalid and we will add a failure message for this failing attribute.
        $validatable = $this->isValidatable($rule, $attribute, $value);

        if ($rule instanceof RuleContract) {
            return $validatable
                    ? $this->validateUsingCustomRule($attribute, $value, $rule)
                    : null;
        }

        $method = "validate{$rule}";

        if ($validatable && ! $this->$method($attribute, $value, $parameters, $this)) {
            $this->addFailure($attribute, $rule, $parameters);
        }
    }
1200999
protected function validateRequiredIf($attribute, $value, $parameters)
    {
        $this->requireParameterCount(2, $parameters, 'required_if');

        $data = array_get($this->data, $parameters[0]);

        $values = array_slice($parameters, 1);

        if (in_array($data, $values)) {
            return $this->validateRequired($attribute, $value);
        }

        return true;
    }
610649
protected function formatMessage($parameter, $ruleName, $ruleParameter, $message = null)
    {
        $message = $message ?: (isset($this->validateMessages[$ruleName]) ? $this->validateMessages[$ruleName] : $this->validateMessages['default']);
        $message = str_replace(':parameter', $parameter, $message);
        $method  = 'format'.ucfirst(Helper::camelCase($ruleName)).'Message';

        if (method_exists($this, $method)) {
            return $this->$method($ruleParameter, $message);
        }

        return $message;
    }
854832
protected function replaceDifferent($message, $attribute, $rule, $parameters)
    {
        return $this->replaceSame($message, $attribute, $rule, $parameters);
    }
1347947
protected function replaceRequiredWith($message, $attribute, $rule, $parameters)
    {
        return str_replace(':values', implode(' / ', $this->getAttributeList($parameters)), $message);
    }
326943
protected function validateAfter($attribute, $value, $parameters)
    {
        $this->requireParameterCount(1, $parameters, 'after');

        if ($format = $this->getDateFormat($attribute)) {
            return $this->validateAfterWithFormat($format, $value, $parameters);
        }

        if (!($date = strtotime($parameters[0]))) {
            return strtotime($value) > strtotime($this->getValue($parameters[0]));
        } else {
            return strtotime($value) > $date;
        }
    }
891082
protected function validateUsingCustomRule($attribute, $value, $rule)
    {
        if (! $rule->passes($attribute, $value)) {
            $this->failedRules[$attribute][get_class($rule)] = [];

            $messages = (array) $rule->message();

            foreach ($messages as $message) {
                $this->messages->add($attribute, $this->makeReplacements(
                    $message, $attribute, get_class($rule), []
                ));
            }
        }
    }
321123
protected function validateIn( $attribute, $value, $parameters )
	{
		if ( is_array( $value ) && $this->hasRule( $attribute, 'Array' ) )
		{
			return count( array_diff( $value, $parameters ) ) == 0;
		}

		return !is_array( $value ) && in_array( (string) $value, $parameters );
	}
139214
protected function convertRule($rule, $attribute, $type)
	{
		$parsedRule = $this->parseValidationRule($rule);
		$jqueryAttrs = [];
		$ruleMethodName = $this->getRuleMethodName($parsedRule['name']);

		// if method not exists that means it is not implemented yet so return empty array
		if(!method_exists($this, $ruleMethodName))
		{
			return $jqueryAttrs;
		}

		$jqueryAttrs = $this->$ruleMethodName($parsedRule, $attribute, $type);
		
		// if validation messages of laravel is going to be used, convert them too
		if(\Config::get('laravel-to-jquery-validation::useLaravelMessages'))
		{
			$messageMethodName = $this->getMessageMethodName($parsedRule['name']);
			
			// if method not exists, get error message by using default way
			if(!method_exists($this, $messageMethodName))
			{
				$jqueryAttrs = $jqueryAttrs + $this->getErrorMessage($parsedRule['name'], $attribute);
			}
			else
			{
				$jqueryAttrs = $jqueryAttrs + $this->$messageMethodName($parsedRule, $attribute, $type);
			}
		}

		return $jqueryAttrs;
	}