PHPackages                             abdelrahmandwedar/selective - 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. [Validation &amp; Sanitization](/categories/validation)
4. /
5. abdelrahmandwedar/selective

ActiveLibrary[Validation &amp; Sanitization](/categories/validation)

abdelrahmandwedar/selective
===========================

A Laravel package to use Redis bloom filters for super-fast validation

30PHPCI failing

Since Jun 15Pushed 1mo agoCompare

[ Source](https://github.com/AbdelrahmanDwedar/selective)[ Packagist](https://packagist.org/packages/abdelrahmandwedar/selective)[ RSS](/packages/abdelrahmandwedar-selective/feed)WikiDiscussions main Synced 2w ago

READMEChangelogDependenciesVersions (2)Used By (0)

Selective
=========

[](#selective)

Selective is a Laravel package that provides **super-fast, Redis bloom filter-backed validation rules** for `unique` and `exists` checks.

When you have millions of rows, running standard `unique:users` or `exists:users` validation on every request can be expensive, causing database strain and slowing down your application.

Selective solves this by adding a probabilistic data structure (a Bloom Filter) in front of your database. When validating, Selective checks the bloom filter in Redis first:

- If the bloom filter says the record **doesn't exist**, validation passes (or fails for `exists`) instantly without touching the database.
- If the bloom filter says the record **might exist**, Selective automatically falls back to standard database validation to confirm.

Requirements
------------

[](#requirements)

- PHP 8.2+
- Laravel 10.0+ or 11.0+
- **Redis with the RedisBloom module installed** (e.g. `redis-stack`)
- Predis or PhpRedis extension

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

[](#installation)

You can install the package via composer:

```
composer require abdelrahmandwedar/selective
```

Publish the config file:

```
php artisan vendor:publish --tag="selective-config"
```

Usage
-----

[](#usage)

### Validation Rules

[](#validation-rules)

Use the rules exactly like you would use Laravel's standard rules.

#### BloomUnique

[](#bloomunique)

Validates that a given attribute does not exist in a database table.

```
use AbdelrahmanDwedar\Selective\Rules\BloomUnique;

$request->validate([
    'email' => ['required', 'email', new BloomUnique('users', 'email')],
]);
```

Ignoring a given ID (e.g. during updates):

```
new BloomUnique('users', 'email')->ignore($user->id)
```

#### BloomExists

[](#bloomexists)

Validates that a given attribute exists in a database table.

```
use AbdelrahmanDwedar\Selective\Rules\BloomExists;

$request->validate([
    'email' => ['required', 'email', new BloomExists('users', 'email')],
]);
```

### Auto-Syncing with Eloquent

[](#auto-syncing-with-eloquent)

To keep your bloom filters automatically updated when you create or update records, use the `HasBloomFilters` trait on your Eloquent models:

```
namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use AbdelrahmanDwedar\Selective\Traits\HasBloomFilters;

class User extends Model
{
    use HasBloomFilters;

    // Define which columns should be synced to bloom filters
    protected array $bloomFilters = ['email', 'username'];
}
```

*Note: Bloom filters do not support deletion. When a model is deleted, the item remains in the filter. This is fine because the fallback database check will handle the "false positive" when checking the deleted item.*

### Artisan Commands

[](#artisan-commands)

#### Seed a Bloom Filter

[](#seed-a-bloom-filter)

If you are adding this package to an existing project, you need to populate the bloom filters with your existing data:

```
php artisan bloom:seed users email
```

You can use the `--fresh` option to delete any existing filter and recreate it, or `--error-rate` and `--capacity` to override defaults.

#### View Filter Status

[](#view-filter-status)

View information about your bloom filters:

```
# Show info for a specific filter
php artisan bloom:status users email

# Show info for all selective filters
php artisan bloom:status
```

#### Clear Filters

[](#clear-filters)

Delete bloom filters:

```
# Clear a specific filter
php artisan bloom:clear users email

# Clear all selective filters
php artisan bloom:clear --all
```

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

[](#configuration)

You can configure the package in `config/selective.php`:

- `default_error_rate`: The acceptable probability of false positives (default: `0.01` or 1%).
- `default_capacity`: The default expected capacity of the bloom filter (default: `1000`).
- `redis_connection`: The Redis connection to use from `config/database.php` (default: `'default'`).
- `key_prefix`: Prefix for Redis keys (default: `'selective:'`).
- `fallback_on_error`: If true, gracefully falls back to DB validation if Redis is down (default: `true`).
- `auto_reserve`: Automatically create filters if they don't exist (default: `true`).

How it works
------------

[](#how-it-works)

1. You define a rule: `new BloomUnique('users', 'email')`.
2. A user submits an email.
3. Selective checks the Redis bloom filter `selective:users:email`.
4. If the filter returns `0` (definitely not in filter): validation passes instantly.
5. If the filter returns `1` (might be in filter): Selective queries the `users` table to confirm if it's a real hit or a false positive.
6. Validation passes or fails based on the DB result.

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

21

—

LowBetter than 17% of packages

Maintenance61

Regular maintenance activity

Popularity4

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity13

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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/2c4ce958f54fdb1cc4b83d4c485070d68c1aa68298ff7d9da3baf9daa9630be5?d=identicon)[AbdelrahmanDwedar](/maintainers/AbdelrahmanDwedar)

---

Top Contributors

[![AbdelrahmanDwedar](https://avatars.githubusercontent.com/u/67812625?v=4)](https://github.com/AbdelrahmanDwedar "AbdelrahmanDwedar (22 commits)")

### Embed Badge

![Health badge](/badges/abdelrahmandwedar-selective/health.svg)

```
[![Health](https://phpackages.com/badges/abdelrahmandwedar-selective/health.svg)](https://phpackages.com/packages/abdelrahmandwedar-selective)
```

###  Alternatives

[drupal/coder

Coder is a library to review Drupal code.

3045.9M586](/packages/drupal-coder)[hybridlogic/validation

A simple, extensible validation library for PHP with support for filtering and validating any input array along with generating client side validation code.

641.1k](/packages/hybridlogic-validation)

PHPackages © 2026

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