You should be able to use eloquent casting on your model to set the format to what you want
protected $casts = [
'time' => 'datetime:H:i:s',
];
https://laravel.com/docs/5.8/eloquent-mutators#array-and-json-casting
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I have this array:
$realtime_labels_array = $latestfeed72->pluck('time')->toArray();
I'd like to pluck 'time' in this format
date('H:i:s', $this_array)
This will convert the array you gave (using first 4 timestamps from your post) into the same array using H:i:s. I don't know if it's what you need for charts to work, but it should do what your original question asks according to my test shown below.
>>> $dates = [1552079470, 1552079460, 1552079450, 1552079440];
=> [
1552079470,
1552079460,
1552079450,
1552079440,
]
>>> $formattedDates = array_map(function($time) { return date("H:i:s", $time); }, $dates);
=> [
"21:11:10",
"21:11:00",
"21:10:50",
"21:10:40",
]
Please or to participate in this conversation.