Posts Learn Components Snippets Categories Tags Tools new About

How to Limit Laravel Eloquent Result

Learn how to limit laravel eloquent result using take, limit and pagination

Created on Nov 18, 2021


Sometimes you might want to limit the eloquent result returned from the DB and to do that you can specify using the "take()" method or the "limit()" method.

Limit Eloquent Result Using Using take() and limit()

For example, let's say you want to limit the querying number of "posts" and to do that you can write your code like the following.

use App\Models\Post;

// using take()

// using limit()

Limit Eloquent Result Using Pagination

Sometimes you might also want to use the pagination approach and to do that you can write your code like below.

use App\Models\Post;

$posts = Post::query()->paginate(20);

If you like our tutorial, do make sure to support us by being our Patreon or buy us some coffee ☕️