- How do I install and use mozex/laravel-searchable?
- Install it with composer require mozex/laravel-searchable, then add the Searchable trait to your Eloquent model and declare the columns and relations you want to search. There is no service provider registration, config file, or migration to run. After that you can call Model::search('term') anywhere in your application and chain normal query methods such as where() and orderBy() around it.
- Which Laravel and PHP versions does laravel-searchable support?
- As of version 1.3.0 the package requires Laravel 12.69.0 or newer, or Laravel 13.30.0 or newer, with PHP 8.2 on the Laravel 12 line and PHP 8.3 on the Laravel 13 line. Laravel 11 support was dropped because those releases are affected by upstream security advisories that are only fixed in 12.69.0 and 13.30.0. If your app runs Laravel 11 or an early 12.x release, Composer silently resolves to 1.2.2 rather than failing, so check composer.lock if you expected the latest version.
- Can I use laravel-searchable together with Laravel Scout?
- Yes, the two packages coexist and can even be used on the same model. Both add a search() method, so if the model already uses Scout you must alias one trait or call the package method through applySearch() instead. This package only performs SQL-based search, so it does not replace Scout's engine-backed relevance ranking or typo tolerance.
- Does it support searching through relations and polymorphic relations?
- Yes. You can search direct columns, BelongsTo and HasMany relation columns, polymorphic relations such as comments on posts or videos, and even relations stored on a different database connection. Relation searches are built as subqueries so the whole result set still comes back from a single chained Eloquent query. This makes it a good fit for hierarchical, multi-tenant, or polymorphic data models.
- Why are my cross-database search results truncated?
- For relations on a separate connection the package first fetches matching IDs from that connection, then runs a WHERE IN query on the main connection with a hard cap of 50 IDs by default. When more related records match, results are silently cut off. Raise externalLimit on that relation and validate the behaviour against realistic data volumes before shipping.
- What are the performance limits of laravel-searchable on large tables?
- Searches use LIKE with leading and trailing wildcards, which forces a full table scan and means ordinary indexes on the search columns will not help. It stays comfortable for small and mid-sized tables but degrades noticeably beyond roughly 100K rows per table, and correlated subqueries for relation search add extra overhead. For heavier workloads add pg_trgm on PostgreSQL or fall back to Scout with Meilisearch or Algolia.
- Does laravel-searchable integrate with Filament?
- Yes, optional Filament v3+ integration ships with the package and gives you ranked table search plus global search with no manual configuration. This removes a lot of glue code when building admin panels and MVPs. Filament is not a dependency of the core package, so it is only pulled in when you actually use that integration.
- How do I limit which columns are searched or order results by relevance?
- Columns and relations are declared on the model, and you can narrow a single query using the in, include, and except filters, for example Model::search('term')->in(['name', 'email']). Multi-word search terms are supported, and relevance ordering lets you sort results by match weight instead of plain column order. All of this chains cleanly with existing where() and orderBy() clauses.
- Which databases are supported and is the search case-insensitive?
- MySQL, PostgreSQL, and SQLite are all supported. Case sensitivity for LIKE is database-dependent: SQLite's LIKE is case-insensitive for ASCII characters only, while PostgreSQL's default LIKE is case-sensitive. Test your queries on the same engine you run in production instead of assuming MySQL behaviour.
- When should I use this package instead of Scout or a full-text search engine?
- Choose it when SQL-only multi-column, relation, and morph search is enough and you want zero extra infrastructure, config, or migrations, such as admin panels, internal tools, or serverless deployments. Reach for Scout with Meilisearch, Algolia, or Typesense when you need fuzzy matching, stemming, typo tolerance, or relevance scoring at scale. The two approaches can run side by side on the same models if you alias the conflicting search methods.