简体   繁体   中英

Get latest date from array of models with Eloquent in laravel

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?

Model::latest('used_at')->first();

https://laravel.com/docs/8.x/queries#latest-oldest

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM