Download the PHP package jabbtech/searchable without Composer
On this page you can find all versions of the php package jabbtech/searchable. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package searchable
Laravel Searchable
Laravel trait to add a search
method for Eloquent which performs prioritized searches in a model.
Installation
Configuration
Import the SearchableTrait
class and add a $searchable
property to your model to specify the columns to make searchable and their priority in search results. Columns with higher values are more important:
Basic Usage
Using the search
method on a query builder instance builds a query that searches through your model using Laravel's Eloquent. The most basic call to search
requires a single argument, a search string.
The search
method should be compatible with any eloquent method (with exceptions for SQL Server):
Accepted Relevance Threshold
The second argument changes is an integer that can change the default threshold for accepted relevance. By default, the threshold for accepted relevance is the sum of all attribute relevance divided by 4.
Returning all users matching the search in order of relevance:
Prioritize Full Text Search
The third argument is a boolean which prioritizes matches that include the multi-word search. By default, multi-word search terms are split and Searchable searches for each word individually. Relevance plays a role in prioritizing matches that matched on multiple words.
Prioritizing matches containing "John Doe" above matches containing only "John" or "Doe":
Full Text Matches Only
The fourth argument is a boolean which allows searching for full text mathces only.
Excluding matches that only matched "John" OR "Doe".
SQL Server
When used with SQL Server the search
method supports most eloquent methods with some limitations.
- It is strongly recommended (and required in some cases) that the
select
method is used- Column constraints of tables you will join to need to be included in the
select
method - Column required by the
where
method need to be included in theselect
method
- Column constraints of tables you will join to need to be included in the
- Most methods need to be used before the
search
methodjoin
leftJoin
crossJoin
where
- Include
orderBy('relevance', 'desc')
after thesearch
method
How does it work?
Searchable builds a query that searches through your model using Laravel's Eloquent. Here is an example query
Model
Search
Result
Credits
Contributing
Anyone is welcome to contribute. Fork, make your changes, and then submit a pull request.
All versions of searchable with dependencies
illuminate/database Version ^6.0|^7.0|^8.0|^9.0
ext-mbstring Version *