README
This commit is contained in:
parent
1553f3116a
commit
ff61692809
@ -9,6 +9,12 @@ Element Search is available on composer. To install, simply run:
|
|||||||
composer require element/search
|
composer require element/search
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Then, add the following line to the `$providers` array in the `config/app.php` file:
|
||||||
|
|
||||||
|
``` php
|
||||||
|
Element\Search\SearchServiceProvider::class,
|
||||||
|
```
|
||||||
|
|
||||||
## Use
|
## Use
|
||||||
|
|
||||||
Making your models searchable is easy. The models simply need to implement the ```php Element\Search\SearchableContract ```
|
Making your models searchable is easy. The models simply need to implement the ```php Element\Search\SearchableContract ```
|
||||||
@ -65,5 +71,5 @@ any string you wish to search for. Additionally, you don't have to worry about r
|
|||||||
or capital letters from your search string, the function does it automatically.
|
or capital letters from your search string, the function does it automatically.
|
||||||
|
|
||||||
The search function, whether in the model, or called from the facade, returns the models in the form
|
The search function, whether in the model, or called from the facade, returns the models in the form
|
||||||
of a \Laravel\Database\Eloquent\Collection collection. This allows you to perform all the usual
|
of a \Laravel\Database\Eloquent\Collection` collection. This allows you to perform all the usual
|
||||||
functions you would be able to perform on a database query.
|
functions you would be able to perform on a database query.
|
||||||
|
@ -10,8 +10,16 @@ namespace Element\Search;
|
|||||||
|
|
||||||
class Search {
|
class Search {
|
||||||
|
|
||||||
/* @var $model \Illuminate\Database\Eloquent\Model */
|
/**
|
||||||
|
* Searches the collection of given $model type for
|
||||||
|
* $string and returns the results.
|
||||||
|
*
|
||||||
|
* @param SearchableContract $model
|
||||||
|
* @param $string
|
||||||
|
* @return \Illuminate\Support\Collection
|
||||||
|
*/
|
||||||
public function search( SearchableContract $model, $string ){
|
public function search( SearchableContract $model, $string ){
|
||||||
|
/* @var $model \Illuminate\Database\Eloquent\Model */
|
||||||
$query = $this->formatQuery( $string );
|
$query = $this->formatQuery( $string );
|
||||||
$models = $model->all();
|
$models = $model->all();
|
||||||
$returns = [];
|
$returns = [];
|
||||||
@ -114,6 +122,13 @@ class Search {
|
|||||||
return collect( $returns );
|
return collect( $returns );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Formats the string into an array of non-punctuated,
|
||||||
|
* non-duplicated, lowercase words.
|
||||||
|
*
|
||||||
|
* @param $string
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
public function formatQuery( $string ){
|
public function formatQuery( $string ){
|
||||||
$words = explode(' ', $string);
|
$words = explode(' ', $string);
|
||||||
$return = [];
|
$return = [];
|
||||||
|
Loading…
Reference in New Issue
Block a user