johnnw

Validation error using datepicker

Posted 9 months ago by johnnw

Im using datepicker in a input field. The datepicker use this format "dd/mm/yy". When I submit the form I get a laravel validation error "The date date is not a valid date." Do you know how to fix?

Laravel

$this->validate($request, [
    'date' => 'required|date',
]);
$pdf = Pdf::create([
    'date' => Carbon::parse($request->date)->format('d/m/Y'),
]);

HTML

<div class="form-group col-md-6">
    <label for="date"Date</label>
    <div class="input-group date" data-provide="datepicker">
        <input type='text' class="form-control"
               value="{{ old('date') }}" name="date" placeholder="DD/MM/YYY"/>
        <span class="input-group-addon"><i class="fa fa-calendar text-primary" aria-hidden="true"></i></span>
    </div>
</div>

JS Format:

$( ".input-group.date" ).datepicker({
    format: 'dd/mm/yy'
});

Please sign in or create an account to participate in this conversation.

Laracasts Mascot

Hi, Have We Met Yet?

Did you know that, in addition to the forum, Laracasts includes well over 1000 lessons on modern web development? All for the price of one lunch out per month.

Sign Me Up

Channels

Reply to

Use Markdown with GitHub-flavored code blocks.