-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cfe7273
commit 63505c4
Showing
6 changed files
with
793 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.idea | ||
vendor | ||
composer.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,72 @@ | ||
# laravel-searchable | ||
Searchable trait for Laravel Eloquent models | ||
# Laravel Searchable | ||
|
||
This package makes it easy to search your Laravel models. | ||
|
||
## Installation | ||
|
||
You can install the package via composer: | ||
|
||
```bash | ||
composer require craftcodery/laravel-searchable | ||
``` | ||
|
||
## Usage | ||
|
||
### Preparing your models | ||
|
||
In order to search through models you'll have to use the `Searchable` trait and add the `toSearchableArray` method. | ||
|
||
```php | ||
namespace App\Models; | ||
|
||
use Illuminate\Database\Eloquent\Model; | ||
use CraftCodery\Searchable; | ||
|
||
class User extends Model | ||
{ | ||
use Searchable; | ||
|
||
/** | ||
* Get the searchable data array for the model. | ||
* | ||
* @return array | ||
*/ | ||
public function toSearchableArray() | ||
{ | ||
return [ | ||
'columns' => [ | ||
'users.name' => 60, | ||
'users.email' => 60, | ||
'locations.city' => 40, | ||
], | ||
'joins' => [ | ||
'locations' => [ | ||
'users.location_id', | ||
'locations.id' | ||
], | ||
], | ||
'groupBy' => 'users.id' | ||
]; | ||
} | ||
} | ||
``` | ||
|
||
### Searching models | ||
|
||
To search your models, just use the `search` method. | ||
|
||
```php | ||
$users = User::search('john')->get(); | ||
``` | ||
|
||
### Configuring search matchers | ||
|
||
You can configure the different search matchers and weights given to each used by the package. | ||
|
||
``` | ||
php artisan vendor:publish --provider=CraftCodery\Searchable\SearchableServiceProvider --tag="config" | ||
``` | ||
|
||
## License | ||
|
||
The MIT License (MIT). Please see [License File](LICENSE.md) for more information. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"name": "craftcodery/laravel-searchable", | ||
"description": "Searchable trait for Laravel Eloquent models", | ||
"keywords": [ | ||
"laravel", | ||
"eloquent", | ||
"search" | ||
], | ||
"homepage": "https://github.com/craftcodery/laravel-searchable", | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "Craft Codery" | ||
} | ||
], | ||
"require": { | ||
"php": "^7.2|^8.0", | ||
"laravel/framework": "^6.0|^7.0|^8.0" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"CraftCodery\\Searchable\\": "src/" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
return [ | ||
'matchers' => [ | ||
'exactFullMatcher' => 100, | ||
'exactInStringMatcher' => 100, | ||
'exactMatcher' => 60, | ||
'startOfStringMatcher' => 50, | ||
'acronymMatcher' => 42, | ||
'consecutiveCharactersMatcher' => 40, | ||
'startOfWordsMatcher' => 35, | ||
'inStringMatcher' => 30, | ||
'similarStringMatcher' => 30, | ||
'timesInStringMatcher' => 8, | ||
], | ||
]; |
Oops, something went wrong.