While developing the web application we need server side form validations. Laravel does this task beautifully. In this article I'm going to explain how we can do our form validations in Laravel.
We don't need to write the form validations in our Controller code like generally people does.
Here is an example of writing form validation rules in Laravel.
For example here is the form:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
<form method="post" action="{{url('register')}}">
{{csrf_field()}}
<div class="form-group has-feedback">
<input type="text" name="name" class="form-control" placeholder="Name" value="{{old('name')}}">
<input type="email" name="email" class="form-control" placeholder="Email" value="{{old('email')}}">
<span class="glyphicon glyphicon-envelope form-control-feedback"></span>
</div>
<div class="form-group has-feedback">
<input type="password" name="password" class="form-control" placeholder="Password">
<span class="glyphicon glyphicon-lock form-control-feedback"></span>
</div>
<div class="row">
<!-- /.col -->
<div class="col-xs-4">
<button type="submit" class="btn btn-primary btn-block btn-flat">Register</button>
</div>
<!-- /.col -->
</div>
</form>
|
When you will submit the form it will go to register route like:
1
|
Route::post('/register','Auth\RegisterController@postRegister');
|
It says the register route has routed to 'postRegister' function which is inside the 'RegisterController'. ...