Currently I am using the date with code toDateString() and it is showing the exact result like in the title, 11/01/2011. I want to change the month, 01 to 11 Jan 2011. I’ve tried to use toLocaleDateString() but when I use that it is throwing an error. How can I fix this ? Below are my code,
public function toArray($request)
{
return array_merge(parent::toArray($request), [
'timeslots' => $this->whenLoaded(
'timeslots',
fn () => $this->timeslots->map(fn (AssetTimeslot $assetTimeslot) => [
'id' => $assetTimeslot->id,
'name' => $assetTimeslot->name,
'date' => $assetTimeslot->pivot->date?->toDateString(),
'start_time' => $assetTimeslot->timeslot ? $assetTimeslot->timeslot->start_time : '',
'end_time' => $assetTimeslot->timeslot ? $assetTimeslot->timeslot->end_time : '',
])->groupBy('date')
),
]);
}
}