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();
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();
}