github.com/tucker-eric/eloquentfilter ↗

An Eloquent Way To Filter Laravel Models And Their Relationships

An animated visualization of tucker-eric/eloquentfilter's Git history from March 2016 to October 2020, built by 15 contributors. The codebase reached 285 lines, mostly PHP. The video runs 1 minute 27 seconds.

Render your own repo

Turn any GitHub repository into a video like this — free sample in seconds.

Visualize your own →

Open this visualization on its own page →

Language

PHP

Contributors

15

Lines of Code

285

From

2016-03-04

To

2020-10-20

Advertisement

About tucker-eric/eloquentfilter

Eloquent Filter is a PHP package for Laravel that simplifies filtering Eloquent models and their relationships through a structured, convention-based approach. Instead of writing complex nested conditional queries to filter models by multiple parameters, developers can define filter logic in dedicated filter classes that automatically map query parameters to filter methods using a camel-cased naming convention.

The package allows developers to implement the `Filterable` trait on any Eloquent model, which enables calling a `filter()` method that processes query input and applies constraints. Filter classes follow a predictable naming pattern (like `UserFilter` for the `User` model) and use intuitive method definitions where the method name corresponds to the query parameter. The package automatically handles common cases like ignoring empty values, dropping `_id` suffixes from parameters, and providing helper methods for common SQL patterns like LIKE queries with wildcards.

A notable feature is the built-in support for filtering by related models through two approaches: the `$relations` array for declaratively mapping related model filters, and the `related()` method for defining local filtering logic on relationships. Both methods use `whereHas()` under the hood to nest relationship constraints efficiently. The package also includes pagination helpers, dynamic filter selection, blacklist/whitelist method support for controlling which methods execute, and setup hooks that run before any filters are applied. Optional service provider registration enables artisan commands for generating filter classes.

Advertisement

Share this video