本文整理汇总了PHP中Illuminate\Validation\Validator::setCustomMessages方法的典型用法代码示例。如果您正苦于以下问题:PHP Validator::setCustomMessages方法的具体用法?PHP Validator::setCustomMessages怎么用?PHP Validator::setCustomMessages使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Validation\Validator
的用法示例。
在下文中一共展示了Validator::setCustomMessages方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: validateData
/**
* Validates the supplied data against the options rules
*
* @param array $data
* @param array $rules
* @param array $messages
*
* @param mixed
*/
public function validateData(array $data, array $rules, array $messages)
{
if ($rules) {
$this->customValidator->setData($data);
$this->customValidator->setRules($rules);
$this->customValidator->setCustomMessages($messages);
//if the validator fails, kick back the errors
if ($this->customValidator->fails()) {
return implode('. ', $this->customValidator->messages()->all());
}
}
return true;
}
示例2: check
/**
* Check the hidden captcha's values
*
* @param array $values Posted values
* @param integer $minLimit [optional] Submission minimum time limit in seconds (default = 0)
* @param integer $maxLimit [optional] Submission maximum time limit in seconds (default = 1200)
* @return boolean
*/
public static function check($values, $minLimit = 0, $maxLimit = 1200, Validator $validator)
{
// Check post values
if ($values === null || !isset($values['token']) || !isset($values['name'])) {
$validator->setCustomMessages(['hiddencaptcha' => trans('hiddencaptcha::error.novalues')]);
return false;
}
// Hidden field is set
if ($values['name'] !== '') {
$validator->setCustomMessages(['hiddencaptcha' => trans('hiddencaptcha::error.autofill')]);
return false;
}
// Get the token values
$token = Crypt::decrypt($values['token']);
$token = @unserialize($token);
// Token is null or unserializable
if (!$token || !is_array($token) || empty($token)) {
$validator->setCustomMessages(['hiddencaptcha' => trans('hiddencaptcha::error.token')]);
return false;
}
// Check time limits
$now = time();
if ($now - $token['timestamp'] < $minLimit || $now - $token['timestamp'] > $maxLimit) {
$validator->setCustomMessages(['hiddencaptcha' => trans('hiddencaptcha::error.time_limit')]);
return false;
}
// Check the random posted field
if (!isset($values[$token['random_field_name']])) {
$validator->setCustomMessages(['hiddencaptcha' => trans('hiddencaptcha::error.random_field')]);
}
// Check if the random field value is similar to the token value
$randomField = $values[$token['random_field_name']];
if (!ctype_digit($randomField) || $token['timestamp'] != $randomField) {
$validator->setCustomMessages(['hiddencaptcha' => trans('hiddencaptcha::error.random_field_value')]);
return false;
}
// Check token values
if (!isset($token['session_id'], $token['ip'], $token['user_agent']) && $token['session_id'] !== session_id && $token['ip'] !== Request::ip() && $token['user_agent'] !== $_SERVER['HTTP_USER_AGENT']) {
$validator->setCustomMessages(['hiddencaptcha' => trans('hiddencaptcha::error.invalid_token')]);
return false;
}
// everything is ok, return true
return true;
}