Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Eloquent Filtering Laravel Package

indexzer0/eloquent-filtering

Define allowed filters on your Eloquent models and apply them from simple arrays or request data—no custom query logic. Supports complex, type-based filtering for APIs and dashboards on Laravel 10+ / PHP 8.2+.

View on GitHub
Deep Wiki
Context7

title: 'Whats New v2' version: 'v2' icon: 'sparkles' iconType: 'solid'

Added

FilterType Enum

All core filters provided by this package can be used via string or via new FilterType enum.

Filter::field('name', ['$like']);
Filter::field('name', [FilterType::LIKE]);

Required Filters

Filters can be marked as required.

Filter::field('name', [FilterType::LIKE])->required();

Pivot Filters

Pivot filter support for BelongsToMany and MorphToMany relationships.

Filter::field('tagged_by', [FilterType::EQUAL])->pivot(Post::class);

Morph Filters

FilterType::HAS_MORPH
FilterType::DOESNT_HAS_MORPH
Filter::morphRelation(
    'subscribable',
    [FilterType::HAS_MORPH],
)->includeRelationFields([
    FoodDeliveryService::class,
    Saas::class,
])

Validation Rules

Validation rules, messages, and attributes can be defined on a per FilterType basis.

Filter::field('status', [
    FilterType::IN->withValidation([
        'value.*' => [Rule::enum(OrderStatus::class)]
    ])
]),

Filter Modifiers

$like:start <Icon icon="link" iconType="solid" />

$like:end <Icon icon="link" iconType="solid" />

$notLike:start <Icon icon="link" iconType="solid" />

$notLike:end <Icon icon="link" iconType="solid" />

$in:null <Icon icon="link" iconType="solid" />

$notIn:null <Icon icon="link" iconType="solid" />

Exceptions

New exceptions for new features.

class InvalidFiltersPayloadException extends InvalidArgumentException
// When filters are passed to ::filter() that are not list arrays.

class InvalidModelFqcnException extends InvalidArgumentException
// When an invalid model string is passed to `Filter::morphType()` or `Filter::morphRelation()->includeRelationFields()`.

class UnsupportedModifierException extends InvalidArgumentException
// When an invalid modifier is passed to ->withModifiers().

class RequiredFilterException extends ValidationException
// When required filter(s) were not applied.

Changed

Qualifying Columns

By default, columns are now qualified with database table when using Filter::field() with any of the core filters provided by this package.

Custom Filters Structure

Custom filters no longer should extend abstract classes.

Removed

Filters

Some dedicated filter classes were removed in favour of new modifiers feature.

  • $like:start.
  • $like:end.
  • $notLike:start.
  • $notLike:end.

allowedFilters() definitions should be updated.

public function allowedFilters(): AllowedFilterList
{
    return Filter::only(
        // old
        // Filter::field('name', ['$notLike:end']),
        // new (start & end modifiers enabled)
        Filter::field('name', [FilterType::NOT_LIKE]),
        // new (just end modifier enabled)
        Filter::field('name', [FilterType::NOT_LIKE->withModifiers('end')]),
    );
}

Filter::all()

Filter::all() has been removed due to not being able to support pivot filters feature. Target::relationAlias() has been removed due to Filter::all() being removed.

Types::except()

Removed due to un-needed complexity.

Config

default_allowed_filter_list has been removed from the config file due to Filter::all() being removed.

All Filterable models default to no filters allowed.

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui
babelqueue/php-sdk
facebook/capi-param-builder-php
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium