Laravel Eloquent take() and skip() Query Example

By Hardik Savani November 5, 2023 Category : Laravel

This tutorial shows you laravel take and skip query example. you will learn laravel eloquent take. i explained simply step by step laravel eloquent skip and take. In this article, we will implement a laravel eloquent skip. Follow bellow tutorial step of take() in laravel 6, laravel 7, laravel 8, laravel 9 and laravel 10.

In this example i will give you very simple example of how to use take() and skip() in laravel application. you can easily use it with laravel 6 and laravel 7 application.

take() will help to get data from a database table with a limit.

skip() will help to skip some records when you fetch data from the database table.

So, let's see bellow examples that will help you how to use take() and skip() eloquent query in laravel.

Example: take()

SQL Query:

select * from `users` limit 10

Laravel Query:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\User;

class UserController extends Controller

{

/**

* Display a listing of the resource.

*

* @return \Illuminate\Http\Response

*/

public function index()

{

$users = User::select("*")

->take(10)

->get();

dd($users);

}

}

Example: skip()

SQL Query:

select * from `users` offset 5

Laravel Query:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\User;

class UserController extends Controller

{

/**

* Display a listing of the resource.

*

* @return \Illuminate\Http\Response

*/

public function index()

{

$users = User::select("*")

->skip(5)

->get();

dd($users);

}

}

Example: take() and skip()

SQL Query:

select * from `users` limit 10 offset 5

Laravel Query:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\User;

class UserController extends Controller

{

/**

* Display a listing of the resource.

*

* @return \Illuminate\Http\Response

*/

public function index()

{

$users = User::select("*")

->skip(5)

->take(10)

->get();

dd($users);

}

}

I hope it can help you...

Shares