- Try to
dd()theCarbon::parse($inputs['expired_at'])->toDateTimeString()and see what you got, check the http://carbon.nesbot.com/docs/ for more details. - Check that the
expired_atis in your Modelfillableproperty.
Laravel timstamp set from Carbon::parse()
Hi Everyone!
I have a db column 'expired_at' which is migrated usin $table->timstamp('expired_at')
My form input of date for is March 26, 2016
I am setting my db column value using
[ ... 'expired_at' => Carbon::parse($inputs['expired_at'])->toDateTimeString(); ... ]
But it inserts timestamp in db 0000-00-00 00:00:00
How can I insert timestamp using Carbon::parse() ?
I would use Carbon::createFromFormat('M d, Y', $inputs['expired_at'])->toDateTimeString();
If you want to just pass the carbon object to eloquent rather than converting it back to a string, add it to the $dates array in your model
protected $dates = ['created_at', 'updated_at', 'expired_at'];
this means that you also automatically get back a Carbon object and can format it however you need in your views etc.
Please or to participate in this conversation.