Insert Date Data Using Laravel’s Eloquent ORM
I have a difficulty in inserting date data with Laravel’s Eloquent ORM. The issue is I didn’t use the right format for the date input. I used mm/dd/yyyy format while the SQL statement requires me to use yyyy/mm/dd format. I need to convert the date form to the approriate format. How I did it? Lets see. 😀
I retrieve the controller with Input::get() and assign it’s value to an Eloquent object. For example:
$event->start_date = date("Y-m-d", strtotime(Input::get('start_date')));
I use strtotime function to convert the date to the number of seconds since January 1 1970 00:00:00 UTC. After that I create a date object with “Y-m-d” format and assign it to start_date attribute.
That’s all! 😀