LoginSignup
1
0

More than 1 year has passed since last update.

【Laravel】Eloquentにlast()がない件

Posted at

環境

Laravel v9.5.1 (PHP v8.1.3)

Eloquentにlast()がない件

RailsでさんざんUser.lastを使っていたので当然Laravelもあると思っていたらなかった…
最新順にソートしてから最初のデータを取り出す。

// created_atを基準にソートされる
User::latest()->first();

User::latest('id')->first();

collectionにはlast()がある

collect([1, 2, 3, 4])->last();

// 4

参考

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0