Merge pull request #1536 from xsbeats/required_with_validation_message
bugfix: added validation message to language file for required_with
This commit is contained in:
@@ -58,6 +58,7 @@ return array(
|
|||||||
"not_in" => "The selected :attribute is invalid.",
|
"not_in" => "The selected :attribute is invalid.",
|
||||||
"numeric" => "The :attribute must be a number.",
|
"numeric" => "The :attribute must be a number.",
|
||||||
"required" => "The :attribute field is required.",
|
"required" => "The :attribute field is required.",
|
||||||
|
"required_with" => "The :attribute field is required with :field",
|
||||||
"same" => "The :attribute and :other must match.",
|
"same" => "The :attribute and :other must match.",
|
||||||
"size" => array(
|
"size" => array(
|
||||||
"numeric" => "The :attribute must be :size.",
|
"numeric" => "The :attribute must be :size.",
|
||||||
@@ -101,4 +102,4 @@ return array(
|
|||||||
|
|
||||||
'attributes' => array(),
|
'attributes' => array(),
|
||||||
|
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -50,6 +50,7 @@ return array(
|
|||||||
"not_in" => "The selected :attribute is invalid.",
|
"not_in" => "The selected :attribute is invalid.",
|
||||||
"numeric" => "The :attribute must be a number.",
|
"numeric" => "The :attribute must be a number.",
|
||||||
"required" => "The :attribute field is required.",
|
"required" => "The :attribute field is required.",
|
||||||
|
"required_with" => "The :attribute field is required with :field",
|
||||||
"same" => "The :attribute and :other must match.",
|
"same" => "The :attribute and :other must match.",
|
||||||
"size" => array(
|
"size" => array(
|
||||||
"numeric" => "The :attribute must be :size.",
|
"numeric" => "The :attribute must be :size.",
|
||||||
@@ -93,4 +94,4 @@ return array(
|
|||||||
|
|
||||||
'attributes' => array('test_attribute' => 'attribute'),
|
'attributes' => array('test_attribute' => 'attribute'),
|
||||||
|
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -666,4 +666,24 @@ class ValidatorTest extends PHPUnit_Framework_TestCase {
|
|||||||
$this->assertEquals($expect, $v->errors->first('test_attribute'));
|
$this->assertEquals($expect, $v->errors->first('test_attribute'));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
/**
|
||||||
|
* Test required_with attribute names are replaced.
|
||||||
|
*
|
||||||
|
* @group laravel
|
||||||
|
*/
|
||||||
|
public function testRequiredWithAttributesAreReplaced()
|
||||||
|
{
|
||||||
|
$lang = require path('app').'language/en/validation.php';
|
||||||
|
|
||||||
|
$data = array('first_name' => 'Taylor', 'last_name' => '');
|
||||||
|
|
||||||
|
$rules = array('first_name' => 'required', 'last_name' => 'required_with:first_name');
|
||||||
|
|
||||||
|
$v = Validator::make($data, $rules);
|
||||||
|
$v->valid();
|
||||||
|
|
||||||
|
$expect = str_replace(array(':attribute', ':field'), array('last name', 'first name'), $lang['required_with']);
|
||||||
|
$this->assertEquals($expect, $v->errors->first('last_name'));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
@@ -863,6 +863,20 @@ class Validator {
|
|||||||
return $message;
|
return $message;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Replace all place-holders for the required_with rule.
|
||||||
|
*
|
||||||
|
* @param string $message
|
||||||
|
* @param string $attribute
|
||||||
|
* @param string $rule
|
||||||
|
* @param array $parameters
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
protected function replace_required_with($message, $attribute, $rule, $parameters)
|
||||||
|
{
|
||||||
|
return str_replace(':field', $this->attribute($parameters[0]), $message);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Replace all place-holders for the between rule.
|
* Replace all place-holders for the between rule.
|
||||||
*
|
*
|
||||||
@@ -1208,4 +1222,4 @@ class Validator {
|
|||||||
throw new \Exception("Method [$method] does not exist.");
|
throw new \Exception("Method [$method] does not exist.");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user