New

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

karabinse/eloquent-searchable

Easily search eloquent models and their relations
8,079 3
Install
composer require karabinse/eloquent-searchable
Latest Version:1.4.3
PHP:^8.2
Laravel:9 – 12
License:MIT
Last Updated:Jan 13, 2026
Links: GitHub  ·  Packagist
Maintainer: Albin N

Easily search eloquent models and their relations

Latest Version on Packagist GitHub Tests Action Status

Installation

You can install the package via composer:

composer require karabinse/eloquent-searchable

Usage

Add the trait and add columns that are searchable.

use Karabin\Searchable\Concerns\IsSearchable;

class User extends Authenticatable
{
    use HasFactory, HasRoles, IsSearchable, Notifiable;

    protected $searchable = [
        'name',
        'email',
        'posts.title'
    ];

The package also includes a custom TermSearchFitler to be used with Laravel Query Builder.

use Karabin\Searchable\Filters\TermSearchFilter;

class UserController extends Controller
{
    public function index(Request $request)
    {
        $users = QueryBuilder::for(User::class)
            ->allowedFilters([
                AllowedFilter::custom('search', new TermSearchFilter),
            ])
            ->paginate($request->query('limit', 10));

        return Inertia::render('User/Index', [
            'users' => UserData::collect($users),
        ]);
    }

Testing

composer test

Credits

License

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

Related Packages

karabinse/laravel-user-invitation

User invitation for Laravel using built in PasswordBroker

6,018 1
karabinse/laravel-commentable

Easily add a commentable trait to a Eloquent model

4,077 0
doctrine/dbal

Powerful PHP database abstraction layer (DBAL) with many features for database s...

651,963,193 9,701
laravel/framework

The Laravel Framework.

610,364,751 34,988

Version History

Version Released PHP Laravel License
1.4.3 ^8.2 ^9.0|^10.0||^11.0||^12.0 MIT
1.4.2 ^8.2 ^9.0|^10.0||^11.0||^12.0 MIT
1.4.1 ^8.2 ^9.0|^10.0||^11.0||^12.0 MIT
1.4.0 ^8.2 ^9.0|^10.0||^11.0||^12.0 MIT
1.3.0 ^8.2 ^10.0||^11.0||^12.0 MIT