Skip to content
albertmoreno edited this page Mar 4, 2016 · 18 revisions

The Laravel Javascript Jalidation package comes with a handy Facade to make creating and rendering your validators easily.


JsValidator::make()

Creates JsValidator instance based on rules and message arrays.

JsValidator::make($rules, $messages, $customAttributes, $selector)
Arguments
  • $rules (array) Validation rules using the Laravel Validation Rules syntax. used. Required
  • $messages (array) Messages showed when validation fails. Optional, if empty default localized laravel messages are used.
  • $customAttributes (array) Custom attribute names. Optional
  • $selector (string) JQuery selector to select the HTML form to be validated. Optional, by default value defined in Configuration will be used.
Returns
Example
$validator = JsValidator::make(
    [
        'name' => 'Dayle',
        'password' => 'lamepassword',
        'email' => '[email protected]'
    ],
    [
        'name' => 'required',
        'password' => 'required|min:8',
        'email' => 'required|email|unique:users'
    ],
    [],
    '#user-form'
)

JsValidator::formRequest()

Creates JsValidator instance based on FormRequest.

JsValidator::formRequest($formRequest, $selector)
Arguments
Returns
Example
$validator = JsValidator::formRequest(
    'App\Http\Requests\StoreBlogPostRequest', 
    '#post-form'
);

JsValidator::validator()

Creates JsValidator instance based on Validator instance.

JsValidator::validator(\Illuminate\Contracts\Validation\Validator $validator, null $selector)
Arguments
Returns
Example
$validator = Validator::make(
    ['name' => 'Dayle'],
    ['name' => 'required|min:5']
);
// ....
$jsval = JsValidator::validator($validator);
Clone this wiki locally