Download the PHP package sebastiansulinski/laravel-search without Composer
On this page you can find all versions of the php package sebastiansulinski/laravel-search. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download sebastiansulinski/laravel-search
More information about sebastiansulinski/laravel-search
Files in sebastiansulinski/laravel-search
Package laravel-search
Short Description A lightweight search component for Laravel 11+.
License MIT
Informations about the package laravel-search
Lightweight search for Laravel 11 +
This package provides a simple, lightweight search component for Laravel 11+.
In contrast to the well known Laravel Scout, it allows models to be associated with more than one index with separate payload for each, which was the much needed feature for my current project.
Currently only typesense
driver is available, but if you feel like contributing a different implementation feel free
to submit a PR.
Installation
Configuration
Start by publishing vendor configuration file search.php
Within the configuration file update parameters for your selected driver and add all models to the models
array:
You can also update the default queue the import job will run on using SEARCH_QUEUE_CONNECTION
environment variable -
otherwise the default queue will be used.
Typesense configuration
Add the following to your services.php
config file and update accordingly:
Models
Each of the models defined within the configuration file under models
array has to implement IndexableDocument
and
use SearchIndexable
trait.
You will also need to implement two methods:
searchableAs
This method returns a list of indexes the record should be listed under.
toSearchableArray
This method returns the payload in the form of array with the key representing corresponding index.
You can also overwrite the shouldBeSearchable
method to indicate whether the record should be indexed.
Register search request parameters for your given implementation
If you are using the built-in controller with the SearchRequest
, within your AppServiceProvider::boot
method add all
relevant validation
rules for a given index.
These will be used with the Indexer::search
method - if you are using different approach for the search, you can
ignore these.
By default, only index
and params
(as array) are validated - whatever you define via this method will be merged to
it.
Disable default routes
To disable default routes add the following to your AppServiceProvider::register
method:
Import records
The following command will import all records for all indexes using default queue.
You can also specify the index you'd like to import:
Remove index and all records
To remove the index and all its records use the following command:
Contributions
Contributions are welcome, but please make sure your code contains all necessary bells and whistles - pint it etc.
All versions of laravel-search with dependencies
laravel/framework Version ^11.30
typesense/typesense-php Version ^4.9
laravel/pint Version ^1.18