Laravel Eloquent skip() and take() Query Example

Laravel 6 , Laravel , Laravel 7

Nicesnippets

35200

16-07-2020


Laravel Eloquent skip() and take() Query Example

Hi Dev,

In this blog, I will learn you skip and take query example in laravel application. I will show you laravel eloquent skip() and take() query example.

Here, i will show you two way to use skip and take query example in laravel application. You'll learn skip and take query in laravel.

You can get to limit the number of results returned from the query, or to skip a given number of results in the query, you may use the skip and take methods:

The use of the skip query in laravel is used to skip the usage data and the use of the take query in laravel to get data.

In the example, There are 10 data in your users table and you want to skip the 4 start data and get the remaining 6 data. Then use the skip and take query in laravel for it. Alternatively, you may use the limit and offset methods.

Here I will give you two-two example for skip and take and limit and offset query in laravel. So let's see the bellow examples.

Example 1 : Skip and Take


/**

* The attributes that are mass assignable.

*

* @var array

*/

public function index()

{

$users = User::skip(4)->take(6)->get();

}

Example 2 : Skip and Take

/**

* The attributes that are mass assignable.

*

* @var array

*/

public function index()

{

$users = DB::table('users')->skip(4)->take(6)->get();

}

Example 1 : Offset and Limit

/**

* The attributes that are mass assignable.

*

* @var array

*/

public function index()

{

$users = User::offset(4)->limit(6)->get();

}

Example 2 : Offset and Limit

/**

* The attributes that are mass assignable.

*

* @var array

*/

public function index()

{

$users = DB::table('users')->offset(4)->limit(6)->get();

}

It will help you...


Recommended Posts