Limit in Laravel 7

Asked

Viewed 31 times

0

I’m with the following Query in Laravel 7.

$itens_carros_melhores_ofertas = Veiculo::where('status', 1)
           ->orderBy('ano', 'DESC')
           ->limit(6,9)
           ->get();

The problem: I need to display the next records, excluding the first three pick up. I think: 3,9, would search for the next 6 records, but that’s not how he behaves, what can I do?

  • Reason for negativity?

  • 1

    Good wasn’t that I negative, you want to take what from the table?

  • novic Obg, then. I have 9 records. In my first query, I have 0.3. I need to search +6 records, out of these 3. In case, 3.9, I think.

  • 1

    I couldn’t use the skip(3), since you want to ignore the first three?

  • I don’t know friend @Woss, I’m new in Laravel (about 30 days I’m using), I used 5 years Codeigniter.

  • 1

    which version of Laravel? is 3.9 even or maybe 4.9 depends on the bank

  • novic woss: I solved with Skip(3), but the version I’m using of Laravel is 7.3

  • Do I exclude the question, or can they include an answer to stay for others? I thank you both.

  • 1

    Don’t exclude the Question, see the answers and move on, further improving your questions

  • 1

    Okay, I really appreciate @novic

Show 5 more comments

1 answer

1


In the documentation in part Limit & Offset has two ways to do this search for parts of records starting from a position:

Example:

$users = DB::table('users')->skip(10)->take(5)->get();

or

users = DB::table('users')->offset(10)->limit(5)->get();

Reference: https://laravel.com/docs/8.x/queries#limit-and-offset

in your case you can do so:

$itens_carros_melhores_ofertas = Veiculo::where('status', 1)
    ->orderBy('ano', 'DESC')
    ->offset(3)
    ->limit(6)
    ->get();

Browser other questions tagged

You are not signed in. Login or sign up in order to post.