Download the PHP package makidizajnerica/laravel-searcher without Composer
On this page you can find all versions of the php package makidizajnerica/laravel-searcher. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download makidizajnerica/laravel-searcher
More information about makidizajnerica/laravel-searcher
Files in makidizajnerica/laravel-searcher
Package laravel-searcher
Short Description Simple model and multi-model search.
License MIT
Homepage https://github.com/MakiDizajnerica/laravel-searcher
Informations about the package laravel-searcher
Laravel Searcher
Simple model and multi-model search.
Installation
Model Preparation
Model should implement MakiDizajnerica\Searcher\Contracts\Searchable
interface, next define attributesForTags()
method inside of it.
This method should return attribute values that will be used as model tags.
After that add MakiDizajnerica\Searcher\Searchable
trait.
Tags will be automaticly created on model creation, updated on model updation, and deleted when model is deleted.
If you want to create model without tags you should use createWithoutTags()
method:
You can also update model without touching its tags:
When deleting model, you can also disable tags deletion:
Models by default will be grouped by their table name, if you want to change that you can define $searchType
property on the model:
Usage
Single Model Search
When searching single model, you can just pass query string to whereTags()
scope.
Multiple Model Search
Method's addModel()
first parametar is class name of the model that will be searched. The second parametar is the scope, you can pass Closure
and array
like the example above.
You can also pass string
which will represent the scope method name:
You may also pass second bool
parametar to the search()
method, if you want strict searcing. By default its set to false, which means that tags will be search in LIKE clause.
When strict search is set to true, only the models with exact tags will be found.
Return value of the search()
method will be MakiDizajnerica\Searcher\Collections\SearchResultCollection
instance.
When rendering the search results, you can do something like this:
Property $results
will represent array of models that you can loop through.
Author
Nemanja Marijanovic ([email protected])
Licence
Copyright © 2021, Nemanja Marijanovic [email protected]
All rights reserved.
For the full copyright and license information, please view the LICENSE file that was distributed within the source root of this package.