Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Gabotronix's avatar

Get latest date from array of models

Hi everybody, I have an array of model entities, each one has a used_at carbon timestamp, I was wondering how can I retrieve the last model to be used (latest used_at) timestamp of the record of models.

$models = Model::all();

How can I get the last used model with Eloquent?

0 likes
2 replies
Sinnbeck's avatar
$model = Model::orderBy('used_at', 'desc')->first();
MichalOravec's avatar
Level 75
$models = Model::latest('used_at')->get();

$latestModel = $models->first();

Or directly

$latestModel = Model::latest('used_at')->first();

Please or to participate in this conversation.