In the documentation it shows the following:
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:
$users = DB::table('users')->skip(10)->take(5)->get();
Alternatively, you may use the limit and offset methods:
$users = DB::table('users')
->offset(10)
->limit(5)
->get();
What are the differences between these two? Are there any differences in execution speed?
With the Query Builder, take()
is just an alias for limit()
:
/**
* Alias to set the "limit" value of the query.
*
* @param int $value
* @return \Illuminate\Database\Query\Builder|static
*/
public function take($value)
{
return $this->limit($value);
}
NB This is not to be confused with take()
on Collections.