Skip to content
pakainfo

Pakainfo

Web Development & Good Online education

  • Home
  • Blog
  • Categories
  • Tools
  • Full Form
  • Guest Post
  • Advertise
  • About
  • Contact Us

PHP Laravel Validation Example Tutorial From Scratch

September 26, 2018 Pakainfo Technology, Laravel, Mysql, Mysqli, php, Programming Leave a comment

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

Contents

  • PHP Laravel Validation Example Tutorial From Scratch
    • Step 1 Include Laravel Routes
    • Step 2 Make a Laravel Controller
    • Step3 make Laravel Blade View interface File
    • Read
    • Summary
    • Related posts

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.

Also Read This πŸ‘‰   Codeigniter drag and drop files Multiple Images Upload

// 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.

Also Read This πŸ‘‰   How to Check Whether a Variable is Set or Not in laravel blade?

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 posts:

  1. Laravel 7 Form Validation rules Tutorial Example
  2. Simple Laravel Form Validation Example
  3. Laravel 6 After Today Validation Tutorial Example
  4. Laravel 6 Required With All Validation Example
  5. Laravel 5.7 Google reCAPTCHA Tutorial with Example
Also Read This πŸ‘‰   Bootstrap 4 Carousel Slider With Thumbnails
existHow to validate unique column when insertlaravel 5.6 validation examplelaravel custom validationlaravel email validation regexlaravel form requestlaravel validation array inputlaravel validation regexlaravel validation uniquelaravel validation unique exceptlaravel validation unique updateList of Laravel validation rulesmaxminPHP Laravel 5.6 Validation example for signup form with error messagesRequired

Post navigation

Previous Post:Automatically Laravel Create dynamic generate sitemap
Next Post:vuejs onchange Event – vuejs v-on change Examples

Advertise With Us

Increase visibility and sales with advertising. Let us promote you online.
Click Here

Write For Us

We’re accepting well-written informative guest posts and this is a great opportunity to collaborate.
Submit a guest post to [email protected]
Contact Us

Freelance web developer

Do you want to build a modern, lightweight, responsive website quickly?
Need a Website Or Web Application Contact : [email protected]
Note: Paid Service
Contact Me

Categories

3movierulz (64) Ajax (464) AngularJS (377) ASP.NET (61) Bio (109) Bollywood (108) Codeigniter (175) CSS (98) Earn Money (69) Education (61) Entertainment (130) fullform (86) Google Adsense (63) Highcharts (77) History (40) Hollywood (109) JavaScript (1357) Jobs (42) jQuery (1423) Laravel (1088) LifeStyle (53) movierulz4 (63) Mysql (1029) Mysqli (890) php (2121) Programming (2332) Python (97) Software (166) Software (88) Stories (98) tamilrockers (104) Tamilrockers kannada (64) Tamilrockers telugu (61) Tech (142) Technology (2392) Tips and Tricks (119) Tools (203) Top10 (478) Trading (90) Trending (71) VueJs (250) Web Technology (105) webtools (191) wordpress (166) World (322)

A To Z Full Forms

Access a complete full forms list with the meaning, definition, and example of the acronym or abbreviation.
Click Here
  • Home
  • About Us
  • Terms And Conditions
  • Write For Us
  • Advertise
  • Contact Us
  • Youtube Tag Extractor
  • Info Grepper
  • Guest Posting Sites
  • Increase Domain Authority
  • Social Media Marketing
  • Freelance web developer
  • Tools
Pakainfo 9-OLD, Ganesh Sco, Kothariya Ring Road, Chokadi, Rajkot - 360002 India
E-mail : [email protected]
Pakainfo

Β© 2023 Pakainfo. All rights reserved.

Top
Subscribe On YouTube : Download Source Code
We accept paid guest Posting on our Site : Guest Post Chat with Us On Skype Guest Posting Sites