Laravel Eloquent take() and skip() Query Example

In this example i explain Laravel Eloquent take() and skip() Query Example. I explain easily laravel eloquent take() method and laravel eloquent skip() method. In this post we learn step by step laravel eloquent take and skip.

In this example i give very simple example of how to use take() and skip() in laravel application. You can easily use laravel take and skip method with laravel 6, laravel 7 and laravel 8 application.

Read Also :  How to Solve 419 Page Expired Laravel

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

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

Laravel Eloquent take() and skip() Query Example

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 you understand Laravel Eloquent take() and skip() Query Example.

Read Also :  Laravel Include Blade File with Data Example