I'm trying to insert a date value in a MySQL table like this (using Laravel 5.1):
public function update(Request $request, $id)
{
$user = User::findOrFail($id);
$data = $request->all();
$data['birthdate'] = date("Y-d-m", strtotime($data['birthdate']));
...
$user->fill($data)->save();
It works fine if I insert a date which the day < 12, while it'll be inserted 1970-01-01 if day > 12 !
I've used Eloquent mutators in User model like this :
public function getBirthdateAttribute() {
return date('d/m/Y', strtotime($this->attributes['birthdate']));
}
public function setBirthdateAttribute($value) {
$this->attributes['birthdate'] = Carbon::createFromFormat('Y-m-d', $value);
}
Please what's the matter with my code !?
$data['birthdate'].-or/seperatorsmm/dd/yyyyoryyyy/mm/dd, see docs.php.net/manual/en/datetime.formats.date.php