laravel eloquent select limit code example

Example 1: limit laravel

$posts = Post::all()->limit(10)->get();

Example 2: limit 1 1 in laravel query

$products = $art->products->skip(10)->take(10)->get(); //get next 10 rows

Example 3: eloquent limit vs take

"limit" only works on eloquent ORM or query builder objects 
whereas "take" works on both collections and the ORM or Query Builder objects.

Model::get()->take(20);   // Correct
Model::get()->limit(20);  // Incorrect

Model::take(20)->get()    // Correct
Model::limit(20)->get()   // Correct

Tags:

Php Example