Laravel 5.6 Server Side Validation Example Using Resource Controller

This Laravel tutorial help to understand server side validation using laravel 5.6.The PHP Laravel is the fastest growing PHP MVC Framework.We will apply validation rule into upcoming request using validation class.I am extending my previous laravel tutorial Laravel 5.6 CRUD Tutorial Using Resource Controller.

This Laravel 5 tutorial help to add server side validation into HTML form view template.We will create add new employee record functionality and validate data against non empty input data.

Laravel provides several different approaches to validate form data into your application’s. By default, Laravel’s using ValidatesRequests, Which provides a convenient method to validate incoming HTTP request with a variety of powerful validation rules.

There are following files will participate:

  • /resources/employee/create.blade.html – Used for display data.
  • /controllers/EmployeeController.php – This file will contains all actions method.

You can also check other recommended tutorials of Lumen/Laravel,

Laravel 5.6 Validation Example

Let’s start Laravel Validation Tutorial through server side by taking simple example.You can also add validation client side but its not safe.

Create View file For Laravel validation

We will create view file that have HTML form and elements, We have submit button that used to submit form data to server, The laravel action method will validate form post data against validation rule.

An exception will be thrown to the user with proper error response, if any of the rule fails, If the all validation rules pass, your code will keep executing normally.

Create new view file into resources/views/employee/create.blade.php folder.

Now create action method to add employee record into database.We will write validation rule to validate form data. We will add below code into app/Http/Controllers/ EmployeeController.php file.

As you can see, We have have defined $validation rules and validate using laravel inbuilt validate class.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.