Posted inLaravel / Mysql / Mysqli / php

How to Validate Date String in Laravel?

Today, We want to share with you laravel date validation.In this post we will show you laravel custom validation, hear for date validation like date after, date_format, after_or_equal:date, before:date, before_or_equal:date etc we will give you demo and example for implement.In this post, we will learn about Laravel 6 Custom Dates Validation with an example.

How to use Date Format Validation in Laravel?

date Validation:

public function addMember(Request $request)
{
   
    $request->validate([
        'member_nm' => 'required',
        'email' => 'required|email',
        'join_at' => 'date'
    ]);
  
}

using date_format Validation:

public function addMember(Request $request)
{
   
    $request->validate([
        'member_nm' => 'required',
        'email' => 'required|email',
        'join_at' => 'date_format:m/d/Y'
    ]);
  
}

using after Validation:

public function addMember(Request $request)
{
   
    $request->validate([
        'member_nm' => 'required',
        'email' => 'required|email',
        'join_at' => 'date_format:m/d/Y|after:tomorrow'
    ]);
  
}

using after_or_equal Validation:

public function addMember(Request $request)
{
    $curr_dt = date('m/d/Y');
   
    $request->validate([
        'member_nm' => 'required',
        'email' => 'required|email',
        'join_at' => 'date_format:m/d/Y|after_or_equal:'.$curr_dt
    ]);
  
}

using before Validation:

public function addMember(Request $request)
{
   
    $request->validate([
        'member_nm' => 'required',
        'email' => 'required|email',
        'leave_at' => 'date_format:m/d/Y|before:join_at',
        'join_at' => 'date_format:m/d/Y|after:tomorrow'
    ]);
   
}

before_or_equal Validation:

public function addMember(Request $request)
{
   
    $request->validate([
        'member_nm' => 'required',
        'email' => 'required|email',
        'leave_at' => 'date_format:m/d/Y|before_or_equal:join_at',
        'join_at' => 'date_format:m/d/Y|after:tomorrow'
    ]);
  
}

Start Date and End Date Example:

public function addMember(Request $request)
{
   
    $request->validate([
        'member_nm' => 'required',
        'email' => 'required|email',
        'join_at' => 'date_format:m/d/Y',
        'leave_at' => 'date_format:m/d/Y|after:join_at'
    ]);
   
}

I hope you get an idea about add date format validation in laravel 6, laravel 7 and laravel 8 project..
I would like to have feedback on my infinityknow.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.

I am Jaydeep Gondaliya , a software engineer, the founder and the person running Pakainfo. I'm a full-stack developer, entrepreneur and owner of Pakainfo.com. I live in India and I love to write tutorials and tips that can help to other artisan, a Passionate Blogger, who love to share the informative content on PHP, JavaScript, jQuery, Laravel, CodeIgniter, VueJS, AngularJS and Bootstrap from the early stage.

Leave a Reply

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

We accept paid guest Posting on our Site : Guest Post Chat with Us On Skype