Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: class based filters #159

Merged
merged 8 commits into from
Mar 11, 2021
Merged

Conversation

ryangjchandler
Copy link
Member

This pull request adds support for basic class based filters. This means you can extract a filter into a reusable class that could be applied to multiple resources.

Here's what the class looks like:

class NameFilter extends Filter
{
    protected function setUp()
    {
        $this->name('Name Like a');
    }

    public function apply($query)
    {
        return $query->where('name', 'LIKE', 'a%');
    }
}

The Filter class now has a setUp() method that can be used by class-based filters to set some default arguments. The $name parameter for ::make() and __construct() is also now nullable so class-based filters don't need to provide it but they still can if they don't want to define the name as $name or using $this->name() in setUp().

This pull request also opens up the scope for future enhancements, such as parameter based filters where you could define the fields for the filter / options inside of a class.

A good example of a reusable filter is a ActiveFilter where multiple resources have a common column and column values.

@danharrin danharrin added the enhancement New feature or request label Mar 10, 2021
@ryangjchandler ryangjchandler requested review from danharrin and removed request for danharrin March 11, 2021 00:05
@danharrin danharrin merged commit dcd7cfc into develop Mar 11, 2021
@danharrin danharrin deleted the feature/class-based-filters branch March 11, 2021 00:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants