In your database make sure you have a date field.
Mar 8, 2016
14
Level 5
Unable ton insert date on Database
Hello,
I get a date from a form and I want to insert it on Database. So, this is my controller for format my date:
$request->date_of_birth = Carbon::createFromFormat('d/m/Y', $request->date_of_birth)->format('Y-m-d');
When I make a dd($request->date_of_birth), I'm getting this : "2016-03-08" So everything is ok for me but when I want to insert on database, I got a 0000-00-00 And i can't understand why. I've already searched on forums some solutions like add ->toDateTimeString() but it's not working. Anyone has an idea please ?
Level 41
You cannot do this:
$request->date_of_birth = Carbon::createFromFormat('d/m/Y', $request->date_of_birth)->format('Y-m-d');
There is no magic setter methods in the Request class. Try using the replace method instead.
$request->replace(['date_of_birth' => Carbon::createFromFormat('d/m/Y', $request->date_of_birth)->format('Y-m-d')]);
Please or to participate in this conversation.