I have a field in my DTO class which accepts start_time and end_time as "2:00 AM"
/**
* @var string
*/
#[CastWith(TimeCaster::class)]
public string $start_time; // 01:00 AM example
/**
* @var string
*/
#[CastWith(TimeCaster::class)]
public string $end_time;
Can I parse this format of time using Carbon in my Caster Class
#[\Attribute] class TimeCaster implements Caster
{
public function cast(mixed $value): mixed
{
return Carbon::parse($value)->format();
}
}
I think you use
Carbon::createFromFormatif you want to get only time using timestamp then