fab2s/searchable
A lightweight Laravel package that adds a reusable Searchable trait to Eloquent models, enabling flexible keyword searches across chosen columns without external search engines. Configure searchable fields and get relevant, multi-word query results with minimal setup.
composer require fab2s/searchable.php -v, CI images, and production runtime before upgrading.use Fab2s\Searchable\Searchable;
class Post extends Model
{
use Searchable;
protected $searchable = [
'title',
'body',
];
}
$posts = Post::query()
->search($request->string('q'))
->latest()
->paginate(25)
->withQueryString();
->toSql() and ->getBindings() to confirm how terms are matched and escaped.Post::query()
->search($term)
->published()
->with('author')
->paginate(25);
withQueryString() so search terms survive page navigation.LIKE behavior.composer.lock, CI images, and deployment runtimes all agree.% and _ is handled. If the package does not escape LIKE wildcards, searches may behave unexpectedly or become expensive. Escape them or constrain input.%term% usually prevent normal index usage. Prefer prefix searches where possible, or move to full-text search for large datasets.whereHas, joins, or separate model searches deliberately.toSql(), getBindings(), and query logging. Check whether the final query still uses expected indexes.How can I help you explore Laravel packages today?