Save Date
I have a table and with appointment_at as a column for saving date. How can I save date? I tried the following code but no luck.
$appointmentAt = '2015-05-10 10:00:00';
$newAppointment = Appointment::create([
'user_id' => $userId,
'appointment_at' => $appointmentAt
]);
Use Carbon
$newAppointment = Appointment::create([
'user_id' => $userId,
'appointment_at' => Carbon::now()
]);
Don't forget to import Carbon.
Don't also forget to register your column as a date, so it is always returned as is in your model:
<?php
...
class MyModel extends Eloquent {
protected $dates = ['appointment_at'];
}
@dixitchopra No luck doesn't say anything.
Your code is OK, I would guess the field is not fillable, if it doesn't get saved at all. Otherwise be specific.
I have to convert string into a date format to store in the database.
Please or to participate in this conversation.