29.07.2016 Views

laravel-5

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Validation 390<br />

Defining The Error Message<br />

You will also need to define an error message for your custom rule. You can do so either using<br />

an inline custom message array or by adding an entry in the validation language file. This message<br />

should be placed in the first level of the array, not within the custom array, which is only for attributespecific<br />

error messages:<br />

.<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 />

.<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 }

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

Saved successfully!

Ooh no, something went wrong!