This commit is contained in:
glmdev
2016-07-08 21:52:53 -05:00
parent 1553f3116a
commit ff61692809
2 changed files with 23 additions and 2 deletions

View File

@@ -10,8 +10,16 @@ namespace Element\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 ){
/* @var $model \Illuminate\Database\Eloquent\Model */
$query = $this->formatQuery( $string );
$models = $model->all();
$returns = [];
@@ -114,6 +122,13 @@ class Search {
return collect( $returns );
}
/**
* Formats the string into an array of non-punctuated,
* non-duplicated, lowercase words.
*
* @param $string
* @return array
*/
public function formatQuery( $string ){
$words = explode(' ', $string);
$return = [];