PHPackages                             tecnocampos/dynamic-model-filter - 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. tecnocampos/dynamic-model-filter

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

tecnocampos/dynamic-model-filter
================================

Apply request-based filters to Eloquent models in Laravel

v0.1.3(1y ago)017MITPHPPHP ^8.1

Since Mar 29Pushed 1y ago1 watchersCompare

[ Source](https://github.com/fredcampos3/dynamic-model-filter)[ Packagist](https://packagist.org/packages/tecnocampos/dynamic-model-filter)[ RSS](/packages/tecnocampos-dynamic-model-filter/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (2)Versions (3)Used By (0)

Dynamic Model Filter for Laravel
================================

[](#dynamic-model-filter-for-laravel)

Apply dynamic filters to Eloquent models based on request data — including support for `where`, `whereDate`, `between`, `like`, and nested `relation` filters. Comes with a flexible Blade form component for easy integration.

---

🚀 Installation
--------------

[](#-installation)

### 1. Require the package (for local testing)

[](#1-require-the-package-for-local-testing)

```
composer require tecnocampos/dynamic-model-filter
```

---

⚙️ Setup
--------

[](#️-setup)

The package auto-registers via `ServiceProvider` using Laravel's package discovery.

If you're loading views from the package, they will be available under the namespace:
`dynamicfilters::`

---

✅ Usage
-------

[](#-usage)

### 1. Add the Trait to your Model

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

```
use TecnoCampos\DynamicModelFilter\Traits\FilterRequestScope;

class User extends Model
{
  use FilterRequestScope;

  public static array $filterRequest = [
    'status' => 'text',
    'created_at' => 'date',
    'search' => 'multi|type:like|fields:name,email',
  ];
}
```

---

### 2. Apply Filters in Controller

[](#2-apply-filters-in-controller)

```
$users = User::applyFilters()->paginate();
```

---

🧠 Filter Syntax Reference
-------------------------

[](#-filter-syntax-reference)

Each entry in `public static array $filterRequest` uses the format:

```
field_name => 'type|option1|option2|...'

```

### Supported Types

[](#supported-types)

TypeDescription`text`Basic `where``like``where` with `%value%``date``whereDate``between`Two filters used for range (`first`, `last`)`relation`Uses `whereHas` with nested filters`multi`Search across multiple fields### Extra Options

[](#extra-options)

OptionUsage`first` / `last`Used with `between` filters`field:column`When input name differs from DB field`type:text/like`Type used inside relation or multi-search`relation:name`Relation path (`user.address`)`fields:field1,field2`Used with `multi` type`source:request`Fetch value from `request()` (default)---

🧩 Example: Advanced
-------------------

[](#-example-advanced)

```
public static array $filterRequest = [
  'start_date' => 'between|first|field:created_at',
  'end_date' => 'between|last|field:created_at',
  'status' => 'text',
  'search' => 'multi|type:text|fields:name,email',
  'subscription' => 'relation|type:text|field:id|relation:subscriptions',
];
```

---

🖼 Blade Component (Form) – Optional UI Integration
--------------------------------------------------

[](#-blade-component-form--optional-ui-integration)

You can use the &lt;x-DMF::form /&gt; component to render filter forms automatically based on a simple fields array.

### Basic usage

[](#basic-usage)

```

```

- All submitted fields will persist values using request().
- The component will auto-render the correct field types (text, select, date).

---

### UI Templates

[](#ui-templates)

You can define which template is used (Bootstrap or Tailwind) via config:

1. Set in .env:

```
DMF_TEMPLATE=bootstrap
```

2. Or override in config file config/dynamic-model-filter.php:

```
return [
  'template' => env('DMF_TEMPLATE', 'tailwind'), // or 'bootstrap'
];
```

The component will automatically load one of the following views:

- resources/views/components/bootstrap/filter-form.blade.php
- resources/views/components/tailwind/filter-form.blade.php

---

### Dynamic behavior

[](#dynamic-behavior)

- size: sets the grid column width (1–12) for Bootstrap and Tailwind layouts
- data: associative array for select
- attributes: any custom HTML attributes (multiple, readonly, etc.)
- class: additional CSS classes

---

📅 Date Support (pt\_BR / en)
----------------------------

[](#-date-support-pt_br--en)

The filter handles date input in both BR (`d/m/Y`) and EN (`m/d/Y`) formats automatically using `Carbon` and app locale.

---

✅ Requirements
--------------

[](#-requirements)

- PHP 8.0+
- Laravel 8+

---

🤝 Contributing
--------------

[](#-contributing)

Contributions are welcome! If you find a bug or have an idea for an improvement, feel free to open an issue or submit a pull request.

### How to Contribute

[](#how-to-contribute)

1. **Fork** this repository
2. **Clone** your fork:

```
git clone https://github.com/fredcampos3/dynamic-model-filter.git
```

3. **Create a new branch** for your changes:

```
git checkout -b feature/your-feature-name
```

4. **Make your changes** and commit:

```
git commit -m "Add feature: your description"
```

5. **Push** to your fork:

```
git push origin feature/your-feature-name
```

6. **Open a Pull Request** to the `main` branch of this repository

Please ensure your code follows Laravel conventions and includes relevant tests if applicable.

---

📖 License
---------

[](#-license)

MIT © TecnoCampos

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance49

Moderate activity, may be stable

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity37

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~38 days

Total

2

Last Release

369d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/999cbd5328220d1b7994c9669b1784aec9e3ec4ac736e1c508ef62c4e4fb33c2?d=identicon)[fredcampos3](/maintainers/fredcampos3)

---

Top Contributors

[![fredcampos3](https://avatars.githubusercontent.com/u/63765141?v=4)](https://github.com/fredcampos3 "fredcampos3 (10 commits)")

### Embed Badge

![Health badge](/badges/tecnocampos-dynamic-model-filter/health.svg)

```
[![Health](https://phpackages.com/badges/tecnocampos-dynamic-model-filter/health.svg)](https://phpackages.com/packages/tecnocampos-dynamic-model-filter)
```

###  Alternatives

[anourvalar/eloquent-serialize

Laravel Query Builder (Eloquent) serialization

11320.2M21](/packages/anourvalar-eloquent-serialize)[matanyadaev/laravel-eloquent-spatial

Spatial library for Laravel

3982.9M15](/packages/matanyadaev-laravel-eloquent-spatial)[overtrue/laravel-versionable

Make Laravel model versionable.

585308.0k5](/packages/overtrue-laravel-versionable)[statamic-rad-pack/runway

Eloquently manage your database models in Statamic.

135192.6k5](/packages/statamic-rad-pack-runway)[dragon-code/laravel-deploy-operations

Performing any actions during the deployment process

240173.5k2](/packages/dragon-code-laravel-deploy-operations)[stayallive/laravel-eloquent-observable

Register Eloquent model event listeners just-in-time directly from the model.

2928.9k7](/packages/stayallive-laravel-eloquent-observable)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
