Skip to content

Commit

Permalink
Add preferred search method (alias for perform)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexVanderbist committed Dec 28, 2018
1 parent f4b83a0 commit 43b3ad7
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

All notable changes to `laravel-searchable` will be documented in this file

## 1.1.0 - 2018-12-28

- add preferred `search()` method (alias for `perform()`)

## 1.0.1 - 2018-12-28

- fix passing an array of searchable model attributes to `registerModel`
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ This package makes it easy to get structured search from a variety of sources. H
$searchResults = (new Search())
->registerModel(User::class, 'name')
->registerModel(BlogPost::class, 'title')
->perform('john');
->search('john');
```

The search will be performed case insensitive. `$searchResults` now contains all `User` models that contain `john` in the `name` attribute and `BlogPost`s that contain 'john' in the `title` attribute.
Expand Down Expand Up @@ -89,7 +89,7 @@ With the models prepared you can search them like this:
```php
$searchResults = (new Search())
->registerModel(User::class, 'name')
->perform('john');
->search('john');
```

The search will be performed case insensitive. `$searchResults` now contains all `User` models that contain `john` in the `name` attribute.
Expand All @@ -101,13 +101,13 @@ You can also pass multiple attributes to search through:

$searchResults = (new Search())
->registerModel(User::class, 'first_name', 'last_name')
->perform('john');
->search('john');

// or use an array of model attributes

$searchResults = (new Search())
->registerModel(User::class, ['first_name', 'last_name'])
->perform('john');
->search('john');
```

To get fine grained control you can also use a callable. This way you can also search for exact matches.
Expand Down Expand Up @@ -142,7 +142,7 @@ This is how you can use it:
```php
$searchResults = (new Search())
->registerAspect(OrderSearchAspect::class)
->perform('john')
->search('john')
```

### Rendering search results
Expand Down
5 changes: 5 additions & 0 deletions src/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ public function getSearchAspects(): array
return $this->aspects;
}

public function search(string $query, ?User $user = null): SearchResultCollection
{
return $this->perform($query, $user);
}

public function perform(string $query, ?User $user = null): SearchResultCollection
{
$searchResults = new SearchResultCollection();
Expand Down

0 comments on commit 43b3ad7

Please sign in to comment.