laravel datetime validation code example

Example 1: Date time format for laravel validation

$request->validate([
        'start_date' => 'date_format:d/m/Y',
        'end_date' => 'date_format:d/m/Y'
    ]);

Example 2: laravel date validation

'dob' => 'required|date_format:Y-m-d|after_or_equal:1920-01-01'

Example 3: laravel validation time hours minutes format

public function store(Illuminate\Http\Request $request)
{
    $this->validate($request, [
        'time_start' => 'date_format:H:i',
        'time_end' => 'date_format:H:i|after:time_start',
    ]);

    // do other stuff
}

Example 4: email validation in laravel

'email' => 'required|email|unique:users,email',
//@sujay

Example 5: laravel validate date

'day'            =>  'required|date',

Example 6: laravel validation custom message example

$rules = [
        'name' => 'required',
        'email' => 'required|email',
        'message' => 'required|max:250',
    ];

    $customMessages = [
        'required' => 'The :attribute field is required.'
    ];

    $this->validate($request, $rules, $customMessages);
//@sujay