Skip to content
  • Home
  • Server-Side
    • php
    • Node.js
    • ASP.NET
    • Magento
    • Codeigniter
    • Laravel
    • Yii
    • CRUD
      • CRUD Database Application
      • CRUD operation in Client side
      • CRUD operation with server side
  • JavaScript
    • AngularJS
    • Ajax
    • VueJs
    • jQuery
    • ReactJS
    • JavaScript
    • SEO
  • Programming
    • Android
    • C programming
    • CSS
    • Mysql
    • Mysqli
  • Technology
    • Software
      • webinar software
      • webinar conferencing software
      • soundproof
    • Adsense
      • Google
      • Earn Money
      • Google Adsense
        • Adsense fraud
        • Adsense Secrets
        • Adsense software
        • Adwords advice
        • Adwords strategy
        • Google adwords help
        • How to get google ads
    • Tips and Tricks
    • Interview
    • Insurance
    • Religious
    • Entertainment
      • Bollywood
      • tamilrockers
      • Hollywood
  • Health Care
    • LifeStyle
    • Women
    • Fashion
    • Top10
    • Jobs
  • Tools
    • Screen Resolution
    • WORD COUNTER
    • Online Text Case Converter
    • what is my screen resolution?
  • Guest Post
    • 4cgandhi
    • IFSC Code

PHP Laravel Validation Example Tutorial From Scratch

September 26, 2018 by Pakainfo

Today, We want to share with you PHP Laravel Validation Example Tutorial From Scratch.In this post we will show you Laravel 5.6 FormRequests validation, hear for How to validate unique column when insert,List of Laravel validation rules we will give you demo and example for implement.In this post, we will learn about PHP Laravel 5.6 Validation example for register form with error messages with an example.

PHP Laravel Validation Example Tutorial From Scratch

There are the Following The simple About PHP Laravel Validation Example Tutorial From Scratch Full Information With Example and source code.

As I will cover this Post with live Working example to develop php – Laravel 5.6 form validation unique, so the Validation – Laravel – The PHP Framework for this example is following below.

Step 1 : Include Laravel Routes

routes/web.php

Route::get('register', '[email protected]');
Route::post('register','[email protected]');

Step 2 : Make a Laravel Controller

registerController.php

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Member;

//Laravel 5 Validation Example From Scratch
class registerController extends Controller
{
   
    public function create()
    {
        return view('register');
    }

    public function store()
    {
        request()->validate([
            'name' => 'required|min:2|max:50',
            'mobile' => 'required|numeric',            
            'email' => 'required|email|unique:members',
            'password' => 'required|min:6',                
            'repeat_password' => 'required|min:6|max:20|same:password',

        ], [
            'name.required' => 'Member Name is required',
            'name.min' => 'Member Name must be at least 2 characters.',
            'name.max' => 'Member Name should not be greater than 50 characters.',
        ]);

        $input = request()->except('password','repeat_password');
        $member=new Member($input);
        $member->password=bcrypt(request()->password);
        $member->save();
        return back()->with('success', 'Member created successfully.');
        
    }
}

//bail rule to attribute
'email' => 'bail|required|email|unique:members'

//nullable 
'mobile' => 'nullable|numeric',

Step3 : make Laravel Blade View interface File

register.blade.php

<!DOCTYPE html>
<html>
<head>
    <title>Laravel 5.6 Validation With Custom Rules Example From Scratch - Pakainfo.com</title>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
</head>
<body>

<div class="container pakainfo">
    <h3>Laravel 5.6 Validation With Custom Rules Example From Scratch</h3>
    @if (count($errors) > 0)
      <div class="alert alert-danger">

          <ul>
              @foreach ($errors->all() as $error)
              <li>{{ $error }}</li>
              @endforeach
          </ul>
      </div>

    @endif

    @if ($message = Session::get('success'))
          <div class="alert alert-success">
              <p>{{ $message }}</p>
          </div>
    @endif

    <form action="{{ url('register') }}" method="POST" id="signupForm">
      {{ csrf_field() }}

        <div class="gst form-group {{ $errors->has('name') ? 'has-error' : '' }}">
            <label class="span6 control-label">Name:</label>
            <input type="text" name="name" class="form-control" value="{{ old('name') }}">
            @if ($errors->has('name'))
                <span class="text-danger">{{ $errors->first('name') }}</span>
            @endif
        </div>
        <div class="gst form-group {{ $errors->has('mobile') ? 'has-error' : '' }}">
            <label class="span6 control-label">Mobile:</label>
            <input type="text" name="mobile" class="form-control" value="{{ old('mobile') }}">
            @if ($errors->has('mobile'))
                <span class="text-danger">{{ $errors->first('mobile') }}</span>
            @endif
        </div>
        <div class="gst form-group {{ $errors->has('email') ? 'has-error' : '' }}">
            <label class="span6 control-label">Email:</label>
            <input type="email" name="email" class="form-control" value="{{ old('email') }}">
            @if ($errors->has('email'))
                <span class="text-danger">{{ $errors->first('email') }}</span>
            @endif
        </div>
        <div class="gst form-group {{ $errors->has('password') ? 'has-error' : '' }}">
            <label class="span6 control-label">Password:</label>
            <input type="password" name="password" class="form-control">
            @if ($errors->has('password'))
                <span class="text-danger">{{ $errors->first('password') }}</span>
            @endif
        </div>
        <div class="gst form-group {{ $errors->has('repeat_password') ? 'has-error' : '' }}">
            <label class="span6 control-label">Confirm Password:</label>
            <input type="password" name="repeat_password" class="form-control">
            @if ($errors->has('repeat_password'))
                <span class="text-danger">{{ $errors->first('repeat_password') }}</span>
            @endif
        </div>
        <div class="gst form-group">
            <button class="btn btn-success" type="submit">Submit</button>
        </div>
    </form>
</div>

</body>
</html>

The Laravel exists() function as well as unique(), these two main Laravel rules are used to input fields validate request all the data against check data that is Saved in the mysql database table.

Read Also:  delete Query In Codeigniter Example Tutorial

// laravel validation regex exists example
'member_id' => 'required|exists:members,id'
// laravel custom validation unique example
'email' => 'required|unique:members,email'

We can also simple use the PHP Based Laravel Rule class to main class define the jquery rule data fluently.

use Illuminate\Validation\Rule;

Validator::make($data, [
    'email' => [
       'required',
        Rule::exists('members')->where(function ($query) {
            $query->where('status', 1);
        }),
    ],
]);

Angular 6 CRUD Operations Application Tutorials

Read :

  • Technology
  • Google Adsense
  • Programming

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

Read Also:  text sheet | textsheet | litanswers | textsheet alternative

I hope you get an idea about PHP Laravel Validation Example Tutorial From Scratch.
I would like to have feedback on my Pakainfo.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.


Related FAQ

Here are some more FAQ related to this Article:

  1. Read Also:  Laravel File Upload Validation Rules Example
  2. Read Also:  Simple Laravel CRUD Validation Tutorial
  3. Read Also:  laravel eloquent get specific columns Example
  4. Read Also:  CodeIgniter Login Registration Example Tutorial From Scratch
  5. Read Also:  Laravel 6 After Today Validation Tutorial Example
  6. Read Also:  Dropzone php mysql Example with Demo
  7. Read Also:  Angular 6 Reactive Forms Validation Tutorial Example
  8. Read Also:  How to Integrate Google No CAPTCHA reCAPTCHA using VueJS
  9. Read Also:  How to display Custom Validation Error Messages in laravel
  10. Read Also:  how to skip a line in python | python skip lines starting with #
Categories Laravel, Mysql, Mysqli, php, Programming, Technology Tags exist, How to validate unique column when insert, laravel 5.6 validation example, laravel custom validation, laravel email validation regex, laravel form request, laravel validation array input, laravel validation regex, laravel validation unique, laravel validation unique except, laravel validation unique update, List of Laravel validation rules, max, min, PHP Laravel 5.6 Validation example for signup form with error messages, Required
Post navigation
Automatically Laravel Create dynamic generate sitemap
vuejs onchange Event – vuejs v-on change Examples

Categories

Ajax (418) AngularJS (357) ASP.NET (61) Bollywood (34) Business (16) Codeigniter (141) C programming (13) CSS (62) Earn Money (50) Education (30) Entertainment (40) Events (14) Google Adsense (58) Government (13) Highcharts (77) Hollywood (33) Interview (18) JavaScript (858) Jobs (25) jQuery (935) Laravel (1007) LifeStyle (30) linux (18) Magento (13) Mysql (870) Mysqli (778) Node.js (34) php (1685) Programming (2173) Python (44) ReactJS (33) SEO (22) Software (16) Software (38) tamilrockers (29) Tech (15) Technology (2181) Tips and Tricks (75) Tools (27) Top10 (109) VueJs (249) Web Technology (28) wordpress (135) World (22) Yii (14)
© 2021 Pakainfo • Developed By Pakainfo.com