-
-
Notifications
You must be signed in to change notification settings - Fork 174
FormRequest Validation Example
albertmoreno edited this page Mar 21, 2015
·
6 revisions
If you validates the forms using FormRequest, you can simply put your validation code in the view.
You normally define your FormRequest
StoreBlogPostRequest.php
<?php namespace App\Http\Requests;
use App\Http\Requests\Request;
class StoreBlogPostRequest extends Request {
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'title' => 'required|unique|max:255',
'body' => 'required',
];
}
}
and in the view you can reference it
post_edit.balde.php
<!-- Scripts -->
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.1/js/bootstrap.min.js"></script>
<!-- Laravel Javascript Validation -->
<script type="text/javascript" src="{{ asset('vendor/jsvalidation/js/jsvalidation.js')}}"></script>
{!! JsValidator::formRequest('App\Http\Request\StoreBlogPostRequest'); !!}