I'm trying to get a TimeString from 08:00:00 to 08:00.
I would like to cast time like this:
protected $casts = [
'opens' => 'time:H:i',
'closes' => 'time:H:i',
];
without using mutators like getOpensAttribute().
In my migration I'm using:
$table->time('opens')->nullable();
$table->time('closes')->nullable();
Is it possible?
According to the docs, the only supported cast types are:
integer, real, float, double, string, boolean, object, array, collection, date, datetime, and timestamp.
Therefore you have to convert your time to string either before you store it or after you retrieve it from the database.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With