问题
In my Controller
$items = Item::all();
I want to get the first 6 items only
How to change the code?
回答1:
Use take() method:
$items = Item::take(6)->get();
回答2:
Use take function
$items = Item::take(6)->get();
Check in laravel docs : https://laravel.com/docs/5.2/queries
回答3:
To limit the number of results returned from the query you may use the take() method.
$items = Item::take(6)->get();
回答4:
or this
$items = Item::paginate(6);
来源:https://stackoverflow.com/questions/38930388/laravel-controller-get-limit-number-item