date validation in laravel 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: if any error in blade laravel
@if ($errors->any())
@foreach ($errors->all() as $error)
<div>{{$error}}</div>
@endforeach
@endif
Example 3: laravel validate date
'day' => 'required|date',
Example 4: in laravel date duration validation rule
[
'from' => ['required', 'date_format:Y-m-d', 'before_or_equal:to'],
'to' => ['required', 'date_format:Y-m-d']
]
Example 5: in laravel date duration validation rule
public function store(Request $request)
{
$todayDate = date('m/d/Y');
$request->validate([
'name' => 'required',
'email' => 'required|email',
'start_date' => 'date_format:m/d/Y|after_or_equal:'.$todayDate
]);
}