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

Filter Laravel Eloquent models using simple arrays and request data—no custom query spaghetti. Define allowed filters on your models, support complex search, and keep queries readable, maintainable, and easy to extend for APIs and dashboards.

View on GitHub
Deep Wiki
Context7

title: 'Relations Allowed Fields' version: 'v2' icon: 'plus' iconType: 'solid'

Overview

By default, when specifying an Filter::relation() or Filter::morphRelation(), fields within that relationship are not included in the allowed filter list.

You can specify allowed filters inside a relation in two ways.

includeRelationFields()

Use ->includeRelationFields() on Filter::relation() or Filter::morphRelation().

public function allowedFilters(): AllowedFilterList
{
    return Filter::only(
        Filter::relation('manufacturer', [FilterType::HAS])
            ->includeRelationFields()
    );
}

For Filter::morphRelation(), you should specify the models for which to include the relation fields for.

public function allowedFilters(): AllowedFilterList
{
    return Filter::only(
        Filter::morphRelation(
            'subscribable',
            [FilterType::HAS_MORPH],
        )->includeRelationFields([
            FoodDeliveryService::class,
            Saas::class,
        ])
    );
}

Define allowedFilters

Alternatively, if you don't want to use ->includeRelationFields(), you can define allowedFilters for each Filter::relation() and Filter::morphType().

public function allowedFilters(): AllowedFilterList
{
    return Filter::only(
        Filter::relation(
            target: 'manufacturer',
            types: [FilterType::HAS],
            allowedFilters: Filter::only(
                Filter::field('name', [FilterType::LIKE])
            )
        )
    );
}
public function allowedFilters(): AllowedFilterList
{
    return Filter::only(
        Filter::morphRelation('subscribable', [FilterType::HAS_MORPH],
            Filter::morphType(
                type: FoodDeliveryService::class,
                allowedFilters: Filter::only(
                    Filter::field('name', [FilterType::EQUAL])
                )
            ),
            Filter::morphType(
                type: Saas::class,
                allowedFilters: Filter::only(
                    Filter::field('name', [FilterType::EQUAL])
                )
            ),
        )
    );
}
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.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport