Level 102
$model = Model::orderBy('used_at', 'desc')->first();
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
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?
$models = Model::latest('used_at')->get();
$latestModel = $models->first();
Or directly
$latestModel = Model::latest('used_at')->first();
Please or to participate in this conversation.