Laravel

Laravel 5 Form Validation

Laravel 5 Form Validation

In this tutorial I am going to clearly explain, how to Validate Laravel 5 Form inputs. There is no standard way of using validation process in laravel 4, So some of them write code in controller, or in models or in some custom pages. But in Laravel 5 we have standard way to use Form validation.

Check out How Laravel 4 validation works

How to make Laravel 5 Form Validation

Step 1. Create Table By using Migration
Step 2. Create Route
Step 3. Create Model
Step 4. Create Controller
Step 5. Create Validation Request
Step 6. Map Validation Request to your Controller.
Step 7. Create View
Step 8. Test Validation

Create Table

By using migration command create table
Here My table name is general_settings which contains the details of admin contact email and social website urls.

Which will create the create_general_settings_table.php under migration folder.

create_general_settings_table.php 

Migrate Tablle to Database

Create Route



Here I have create two routes, One to show General Settings Form, Another to store Form inputs.

Create Model

By using command I am going to create Model for general_settings table.

Which will create GeneralSetting.php file under App/Models folder.

GeneralSetting.php 

Create Controller

Which will create GeneralSettingsController.php file under controller folder.

GeneralSettingsController.php

Create Validation Request

Now we are going to create validation request,

It will create GeneralSettingsRequest.php file under Http/Requests folder. Which contains of all request files.

Here I have written my validation Rules also.

Here valid_url is not a predefined Validation Rule,  I have Create Custom Validation rule for my own use

Check How to Create Custom Validation In Laravel

Map Validation Request to your Controller.

Now we are going to Map Our Validation Request to Controller Like below

Create View

Here I have create the form which suits for my table.

I have Already installed Former to my application. So I have called Former here.

How to make Laravel 5 Form Validation

Test Validation

Now Submit your form it will automatically check validation and if it fails it will redirect back to previous page with error messages.

How to make Laravel 5 Form Validation

Thats all, Now you can work out this in your application.
Thanks for reading. If you like this article don’t forget to share and comment.
Happy Coding.