laravel/framework — pull request #1053 by miguelbgouveia (2013-04-23 16:03:14+00:00)
Title: Zero value to return with no limit in take func

In many situations, when using Eloquent objects, we create a function to retrieve a Collection of objects based on a specific filter. Example:

public function getUsersByName ($name, $limit = 0)
{
return User::where('name', 'like', '%'.$name'%')->take($limit)->get();
}

In this kind of functions we want to limit the collection when some limit is specified and retrieve all objects when no limit is specified. To accomplish this we change the take function in order to consider the value 0 as to retrieve all the founded objects. Without this change we have always to implement the previous function like this:

public function getUsersByName ($name, $limit = 0)
{
if ($limit = 0) {
return User::where('name', 'like', '%'.$name'%')->get();
}
else {
return User::where('name', 'like', '%'.$name'%')->take($limit)->get();
}
}