Laravel / Carbon Timestamp 0000-00-00 00:00:00 or received unexpected data. Unexpected data received. Missing data

I have a timestamp in the database and am trying to save a pig. I either get a problem when the timestamp is MySQLempty or I get an error. The format presented is UK standard.

Posting data, I tried some of the following:

$user['crb_date'] = Carbon::createFromFormat('d/m/Y', $data['crb_date']);

$user['crb_date'] = Carbon::createFromFormat('d/m/Y', $data['crb_date'])->toDateTimeString();

// Plus many other more std date(), strtodate() combos

In my model, I have custom getDates that convert dates to Carbon:

public function getDates()
{
    return [
        'last_login',
        'created_at',
        'updated_at',
        'dob',
        'crb_date'
    ];
}

Now, if I update a user with a carbon date, I get the following problem:

Unexpected data found. Unexpected data found. Data missing

However, if I dd($user['crb_date']after the second carbon date conversion, I get

string '2011-05-01 11:20:23' (length=19)

Which looks pretty good to me.

If I remove the accessor on the model, I get it for publication, however I get an empty timestamp

0000-00-00 00:00:00

, , .

, , ? , , , , .

, , .

, - . (Carbon:: createFormFormat... :

public function setCrbDateAttribute($value)
{
     $this->attributes['crb_date'] = \Carbon\Carbon::createFromFormat('d-m-Y h:i', $value);
}

:

public function getDates()
{
    return [
        'last_login',
        'created_at',
        'updated_at',
        'dob',
        'crb_date'
    ];
}

SORTED!

WereWolf , Model, . :

public function setCrbDateAttribute($value)
{
    $this->attributes['crb_date'] = \Carbon\Carbon::createFromFormat('d/m/Y', $value)->toDateTimeString();
}
+4
1

date, , :

public function setCrbDateAttribute($value)
{
     $this->attributes['crb_date'] = \Carbon\Carbon::createFromFormat('d-m-Y h:i', $value);
}

, , 10-12-2014, , hour minute. , , , - , /.

, $value, Carbon , ​​ , .

accessor, , Carbon::createFromFormat().

, date date_format:format, .

+4

All Articles