New

Just launched: Vueblocks, a brand-new search engine for Vue packages! Explore Vueblocks →

craftcodery/laravel-searchable

Searchable trait for Laravel Eloquent models
8,001
Install
composer require craftcodery/laravel-searchable
Latest Version:3.5.0
PHP:^8.2
Laravel:10 – 13
Older releases:6 – 9
License:MIT
Last Updated:May 11, 2026
Links: GitHub  ·  Packagist
Maintainer: aaronhuisinga

Laravel Searchable

This package makes it easy to search your Laravel models.

Installation

You can install the package via composer:

composer require craftcodery/laravel-searchable

Usage

Preparing your models

In order to search through models you'll have to use the Searchable trait and add the toSearchableArray method.

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use CraftCodery\Searchable\Searchable;

class User extends Model
{
    use Searchable;

    /**
     * Get the searchable data array for the model.
     *
     * @return array
     */
    public function toSearchableArray()
    {
        return [
            'columns' => [
                'users.name'  => 60,
                'users.email' => 60,
                'locations.city' => 40,
                'organizations.name' => 40
            ],
            'joins'   => [
                'locations' => [
                    'users.location_id',
                    'locations.id'
                ],
                'organizations' => [
                    // use commas to join on multiple columns, e.g. where
                    // organizations.id equals primary_org_id OR secondary_or_id
                    'users.primary_org_id,users.secondary_org_id',
                    'organizations.id'
                ]
            ],
            'groupBy' => 'users.id'
        ];
    }
}

Searching models

To search your models, just use the search method.

$users = User::search('john')->get();

Configuring search matchers

You can configure the different search matchers and weights given to each used by the package.

php artisan vendor:publish --tag=searchable-config

License

The MIT License (MIT). Please see License File for more information.

Related Packages

iverberk/larasearch

Elasticsearch enabled Eloquent models

15,554 222
laravellegends/eloquent-filter

A simple Eloquent filter to make easy API filtering

22,339 39
archy-bold/eloquent-searchable

A service layer to provide support for search on your Eloquent models. WIP only...

2,002 7
websecret/laravel-search

Laravel Eloquent models with Elasticsearch 2

342 4
filipac/searchable

Eloquent model search trait.

24 2

Version History

Version Released PHP Laravel License
3.5.0 ^8.2 ^10.0|^11.0|^12.0|^13.0 MIT
3.4.0 ^8.2 ^10.0|^11.0|^12.0 MIT
3.3.0 ^8.1 ^10.0|^11.0 MIT
3.2.0 ^8.1 ^10.0|^11.0 MIT
3.1.0 ^8.1 ^10.0 MIT