06.10.2016 Views

laravel-5

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Validation 510<br />

1 "foo" => "Your input was invalid!",<br />

2<br />

3 "accepted" => "The :attribute must be accepted.",<br />

4<br />

5 // The rest of the validation error messages...<br />

When creating a custom validation rule, you may sometimes need to define custom place-holder<br />

replacements for error messages. You may do so by creating a custom Validator as described above<br />

then making a call to the replacer method on the Validator facade. You may do this within the<br />

boot method of a service provider:<br />

1 /**<br />

2 * Bootstrap any application services.<br />

3 *<br />

4 * @return void<br />

5 */<br />

6 public function boot()<br />

7 {<br />

8 Validator::extend(...);<br />

9<br />

10 Validator::replacer('foo', function($message, $attribute, $rule, $parameters\<br />

11 ) {<br />

12 return str_replace(...);<br />

13 });<br />

14 }<br />

Implicit Extensions<br />

By default, when an attribute being validated is not present or contains an empty value as defined by<br />

the required rule, normal validation rules, including custom extensions, are not run. For example,<br />

the unique rule will not be run against a null value:<br />

1 $rules = ['name' => 'unique'];<br />

2<br />

3 $input = ['name' => null];<br />

4

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!