Let's start quickly. If you want to leave some columns in the database and take a few, is there a problem ? of course not
Skip and Take
User::skip(4)->take(6)->get();
DB::table('users')->skip(4)->take(6)->get();
Offset and Limit
User::offset(4)->limit(6)->get();
DB::table('users')->offset(4)->limit(6)->get();
take can be used within a relationship to extract a certain number of products
@foreach ($categories as $category)
@foreach ($category->products->take(4) as $product)
// fields
@endforeach
@endforeach
I hope you enjoyed the code.
Top comments (1)
good info