Download the PHP package masterro/laravel-searchable without Composer
On this page you can find all versions of the php package masterro/laravel-searchable. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download masterro/laravel-searchable
More information about masterro/laravel-searchable
Files in masterro/laravel-searchable
Package laravel-searchable
Short Description Simple fulltext search though Eloquent models
License MIT
Informations about the package laravel-searchable
Laravel simple FULLTEXT search through multiple Eloquent models
This is a small Laravel package allows you to make a global search though multiple Eloquent models and get ordered by relevance collection of results. It uses MATCH AGAINST MySQL queries.
Installation
Step 1: Composer
From the command line, run:
Step 2: Service Provider
If you do not use laravel package auto-discovery you need to register the service provider, open config/app.php
and, within the providers
array, append:
Usage
Register your search models in AppServiceProvider or create your custom one
Then you should implement MasterRO\Searchable\SearchableContract by each registered model, or it will be skipped and define searchable
method
Make sure you added fulltext indicies to your tables
Now you can make search in your controller or where you want
Runtime search model switching
Filtering
Model filter
Search results can be filtered by adding the filterSearchResults()
in your model (like Eloquent global scope)
The example code above will filter the search results and will only return users which have published posts.
Runtime filter
Search results can be filtered by adding custom filter callback
Disabling model filter
Model filters can be skipped in runtime like Eloquent global scopes.
You can specify models to skip filters for
or
Eager load (N+1 issue)
For preventing N+1 issue you can eager load relationships for search results
All versions of laravel-searchable with dependencies
illuminate/pagination Version ^6.0|^7.0|^8.0
illuminate/support Version ^6.0|^7.0|^8.0
illuminate/database Version ^6.0|^7.0|^8.0