laravel/framework — pull request #5835 by Psykar (2014-09-26 00:00:22+00:00)
Title: Parse $dates values when fromDateTime is called

Allows model to be assigned a date like strings, without it having to match the database format exactly.

Main advantage is this allows for more forgiving parsing of incoming json / user formatted dates.
This would fix #5528 - although has similarities to #3799 which was rejected.

IMO, writing a mutator for every date value is not an appropriate solution, particularly if you have a large number of date fields.

If this doesn't get accepted, a workaround is to use a trait, overriding fromDateTime, call the parent and if it fails, parse with Carbon then push it through the parent again.
```
/**
* @see \Illuminate\Database\Eloquent\Model::fromDateTime
*
* Overridden to attenpt a Carbon parse of value if it fails
*
* @param $value
* @return mixed
*/
public function fromDateTime($value)
{
try {
return parent::fromDateTime($value);
} catch (\InvalidArgumentException $e) {
$value = Carbon::parse($value);
return parent::fromDateTime($value);
}
}```