Select the first 10 rows - Laravel Eloquent

前端 未结 3 1354
情话喂你
情话喂你 2021-02-01 00:21

So far I have the following model:

class Listing extends Eloquent {
     //Class Logic HERE
}

I want a basic function that retrieves the first

3条回答
  •  青春惊慌失措
    2021-02-01 01:24

    Another way to do it is using a limit method:

    Listing::limit(10)->get();
    

    This can be useful if you're not trying to implement pagination, but for example, return 10 random rows from a table:

    Listing::inRandomOrder()->limit(10)->get();
    

提交回复
热议问题