From 12c52d5160bff8a9268f751bbdecb74616e506e6 Mon Sep 17 00:00:00 2001 From: Tom Lingham Date: Sat, 14 May 2016 12:11:51 +1000 Subject: [PATCH] Add explanation for how to easily limit the results in README --- README.md | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 222dd45..d48d55c 100755 --- a/README.md +++ b/README.md @@ -64,6 +64,16 @@ $users = Searchy::search('users')->fields('name', 'email')->query('John Smith') ->getQuery()->having('relevance', '>', 20)->get(); ``` +### Limit on results returned + +To limit your results, you can use Laravel's built in DatabaseQuery Builder method and chain further methods to narrow your results. + +```php +// Only get the top 10 results +$users = Searchy::search('users')->fields('name', 'email')->query('John Smith') + ->getQuery()->limit(10)->get(); +``` + ### Searching multiple Columns You can also add multiple arguments to the list of fields/columns to search by. @@ -118,7 +128,7 @@ $users = collect(array_map(function($result) { }, Searchy::users('name', 'email')->query('Andrew')->get())); ``` -All this does it map a function over the Searchy results and then creates a new instance of the User model and hydrates the model using the `fill()` method. +All this does is map a function over the Searchy results and then creates a new instance of the User model and hydrates the model using the `fill()` method. Then once it has an array of all the Eloquent User models, it simply uses the Laravel `collect()` method to return the array as Laravel Collection which is the same as you would receive from querying the Laravel model directly. `get_object_vars()` is simply a PHP method to extract the accessible object variables as an associative array. ## Configuration