Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message
Laravel Searchable

Laravel Searchable Laravel Package

mozex/laravel-searchable

Add a Searchable trait to any Eloquent model to search multiple columns and related data (relations, morphs, even cross-database) via a single ->search() call. Works with Laravel Scout and includes optional Filament table/global search integration.

View on GitHub
Deep Wiki
Context7

Advanced multi-column, relation, and morph search for Laravel Eloquent models

Frequently asked questions about Laravel Searchable
How do I add multi-column search to an Eloquent model in Laravel?
Use the `Searchable` trait on your model. Define `searchable` property with column names (e.g., `['name', 'email']`), then call `$model->search('query')` to search across all specified columns. Supports direct columns, relations, and polymorphic relations out of the box.
Can I search related model data (e.g., posts with comments) with this package?
Yes. Define relations in the `searchable` array (e.g., `['comments.body']`). The package automatically queries related tables using `LIKE` clauses. For polymorphic relations, use `morphs` syntax like `['morphs:taggable']`.
Does mozex/laravel-searchable work with Laravel Scout?
It can coexist, but avoid naming conflicts. Scout’s `search()` method will override the trait’s. Use `applySearch()` or alias the trait method (e.g., `public function mozexSearch()`) to prevent collisions. Ideal for hybrid setups where Scout handles global search and this package handles admin queries.
What Laravel versions and PHP requirements does this package support?
The package requires **Laravel 10+** and **PHP 8.2+**. It’s fully compatible with modern Laravel stacks but may need minor adjustments for older versions (e.g., custom query builders). Always check the [latest docs](https://mozex.dev/docs/laravel-searchable/v1) for updates.
How do I integrate this with Filament for table/global search?
Install the package, then use `Searchable` on your Filament resources. For table search, add `searchable()` to your table columns. For global search, configure the `Searchable` trait in your Filament panel’s `globalSearch` method. Zero-config for basic setups.
Is this package performant for large datasets (e.g., 500K+ rows)?
No—it uses `LIKE '%term%'` queries, which are inefficient for large tables. For datasets >100K rows, consider adding database-specific optimizations (e.g., PostgreSQL’s `pg_trgm` extension) or falling back to Scout/Meilisearch for global searches. Test with your data volume.
How do I search across databases (e.g., MySQL + PostgreSQL) with this package?
Use the `external` syntax in `searchable` (e.g., `['external:posts.title']`). The package supports cross-database relations but limits external queries to **50 IDs by default** (`externalLimit`). Increase this value if needed, but be mindful of performance.
Can I customize which columns are searched dynamically?
Yes. Use the `in()`, `include()`, or `except()` methods on the query to filter columns at runtime. Example: `$model->search('query')->in(['name', 'email'])` or `$model->search('query')->except(['archived'])`.
What if my model already has a `search()` scope? Will this package conflict?
Yes, the trait’s `search()` method will override existing scopes. Rename the trait method (e.g., `public function mozexSearch()`) or use `applySearch()` to merge logic. Check the [Handling Conflicts](https://mozex.dev/docs/laravel-searchable/v1#handling-conflicts) section for solutions.
Are there alternatives to this package for Laravel search?
For SQL-based search, consider `spatie/laravel-searchable` (simpler) or `laravel-scout` (for Algolia/Meilisearch). For full-text search without external engines, PostgreSQL’s `tsvector` or `pg_trgm` are powerful alternatives. This package excels for admin/table searches with relations.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
terminal42/code-quality-tools
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky