3

In my Controller

$items = Item::all();

I want to get the first 6 items only

How to change the code?

Walker Base
  • 179
  • 4
  • 14

4 Answers4

8

Use take() method:

$items = Item::take(6)->get();
Alexey Mezenin
  • 148,626
  • 22
  • 267
  • 261
0

Use take function

 $items = Item::take(6)->get();

Check in laravel docs : https://laravel.com/docs/5.2/queries

Niklesh Raut
  • 31,857
  • 10
  • 68
  • 102
0

To limit the number of results returned from the query you may use the take() method.

$items = Item::take(6)->get();
Amanullah Aman
  • 623
  • 1
  • 12
  • 28
0

or this

$items = Item::paginate(6);
A. Apola
  • 111
  • 1
  • 4
  • 12