Saturday, March 18, 2017

Carbon date saves as 0000-00-00 in Laravel

I am trying to save a date in Laravel, but it keeps defaulting to 0000-00-00.

Migrations setup:

$table->date('audit_date')->nullable();

It needs to be nullable because it's not initially added, this function edits the row.

Controller:

$date = Carbon::createFromFormat('d/m/Y', $request->get('datepicker'))
            ->toDateString();

If I output the $date, it shows "2017-03-16"

Full snippet showing where the date is added:

$date = Carbon::createFromFormat('d/m/Y', $request->get('datepicker'))
           ->toDateString();

    $audit = Score::where('id', 1)->first();
    $audit->audited = 1;
    $audit->audit_date = $date;
    $audit->save();

Why does it save as 0000-00-00?



via Ben

Advertisement