06.10.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 497<br />

1 echo $messages->first('email', ':message');<br />

Retrieving All Error Messages With A Format<br />

1 foreach ($messages->all(':message') as $message) {<br />

2 //<br />

3 }<br />

Custom Error Messages<br />

If needed, you may use custom error messages for validation instead of the defaults. There are several<br />

ways to specify custom messages. First, you may pass the custom messages as the third argument<br />

to the Validator::make method:<br />

1 $messages = [<br />

2 'required' => 'The :attribute field is required.',<br />

3 ];<br />

4<br />

5 $validator = Validator::make($input, $rules, $messages);<br />

In this example, the :attribute place-holder will be replaced by the actual name of the field under<br />

validation. You may also utilize other place-holders in validation messages. For example:<br />

1 $messages = [<br />

2 'same' => 'The :attribute and :other must match.',<br />

3 'size' => 'The :attribute must be exactly :size.',<br />

4 'between' => 'The :attribute must be between :min - :max.',<br />

5 'in' => 'The :attribute must be one of the following types: :values',<br />

6 ];<br />

Specifying A Custom Message For A Given Attribute<br />

Sometimes you may wish to specify a custom error messages only for a specific field. You may do<br />

so using “dot” notation. Specify the attribute’s name first, followed by the rule:

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

Saved successfully!

Ooh no, something went wrong!