PHPackages                             ysm/filterable - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. ysm/filterable

ActiveLibrary[Database &amp; ORM](/categories/database)

ysm/filterable
==============

Laravel Filterable Package for Eloquent Models

1.0.0(8mo ago)8705↑136.8%1MITPHPPHP ^8.0

Since Sep 3Pushed 8mo agoCompare

[ Source](https://github.com/DevYSM/filterable)[ Packagist](https://packagist.org/packages/ysm/filterable)[ RSS](/packages/ysm-filterable/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (1)Versions (2)Used By (0)

YSM Filterable
==============

[](#ysm-filterable)

The `YSM\Filterable` package provides a flexible and reusable way to filter Eloquent queries in Laravel applications. It allows developers to apply dynamic query filters based on HTTP request parameters, with support for whitelisting, blacklisting, aliases, and default values. This package is designed to keep filtering logic separate from controllers and models, promoting clean code and adherence to the Single Responsibility Principle.

Table of Contents
-----------------

[](#table-of-contents)

- [Installation](#installation)
- [Configuration](#configuration)
- [Usage](#usage)
    - [Basic Usage](#basic-usage)
    - [Advanced Use Cases](#advanced-use-cases)
        - [Using Aliases](#using-aliases)
        - [Auto-Applying Filters](#auto-applying-filters)
        - [Whitelisting and Blacklisting Filters](#whitelisting-and-blacklisting-filters)
        - [Setting Default Filter Values](#setting-default-filter-values)
        - [Debugging Applied Filters](#debugging-applied-filters)
- [Contributing](#contributing)
- [License](#license)

Installation
------------

[](#installation)

1. **Install the Package via Composer**: Install the `YSM\Filterable` package using Composer:

    ```
    composer require ysm/filterable
    ```
2. **Publish Configuration (Optional)**: If the package includes a configuration file, publish it to customize settings:

    ```
    php artisan vendor:publish --provider="YSM\Filterable\FilterableServiceProvider"
    ```

    *Note*: If no service provider exists, you can skip this step as the package is ready to use after installation.
3. **Requirements**:

    - PHP 8.0 or higher
    - Laravel 8.x or higher

Configuration
-------------

[](#configuration)

The `YSM\Filterable` package does not require additional configuration out of the box. It integrates seamlessly with Laravel's Eloquent ORM and HTTP request handling. To use it, you need to:

1. Create a filter class that extends `YSM\Filterable\Filterable`.
2. Apply the `InteractWithFilterable` trait to your Eloquent models.

Usage
-----

[](#usage)

### Basic Usage

[](#basic-usage)

The package provides an abstract `Filterable` class and a trait `InteractWithFilterable` to apply filters to Eloquent queries.

#### Step 1: Add the Trait to Your Model

[](#step-1-add-the-trait-to-your-model)

Add the `InteractWithFilterable` trait to your Eloquent model:

```
