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

timurlan156's avatar

Why first() is not using LIMIT in it's query?

Why method first() is not using LIMIT in it's query while it always returns one result?

0 likes
5 replies
rezuankassim's avatar

first() method is to get only the first one in the record. If you want to have other records, you should use get() which will return an amount set by LIMIT

Snapey's avatar
DB::enableQueryLog();

User::where('id',1)->first()

dd(DB::getQueryLog());

array:1 [
  0 => array:3 [
    "query" => "select * from `users` where `id` = ? limit 1"
    "bindings" => array:1 [
      0 => 1
    ]
    "time" => 1.46
  ]
]
saurav77's avatar

@timurlan156 The first() method returns the first element in the collection where get() method returns a collection and first returns a single model instance. So I guess we cannot use limit in first method()

Please or to participate in this conversation.