PHPackages                             roulette/roulette - 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. roulette/roulette

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

roulette/roulette
=================

PHP ORM framework with field lifecycle, authorization, and validation

v2.0.0(1mo ago)415MITPHP &gt;=8.1

Since Dec 28Compare

[ Source](https://github.com/pimlabs/roulette)[ Packagist](https://packagist.org/packages/roulette/roulette)[ Docs](https://github.com/ekodedypurnomo/Roulette)[ RSS](/packages/roulette-roulette/feed)WikiDiscussions Synced yesterday

READMEChangelog (3)Dependencies (1)Versions (7)Used By (0)

Roulette ORM
============

[](#roulette-orm)

A sophisticated PHP ORM that bridges objects and relational databases with a clean, fluent API. Field values go through a full lifecycle pipeline — read → convert → validate → write → render — giving you fine-grained control over every column in every model.

PHP 8.1+ · Framework agnostic · Zero migration files

---

Features
--------

[](#features)

- **Model-driven schema** — prototype declaration is the single source of truth for table structure
- **Field lifecycle pipeline** — reader, converter, validator, writer, renderer per field
- **Mass assignment protection** — `fillable: false` on sensitive fields prevents user data from overwriting them
- **Associations** — HasOne, HasMany, BelongsTo, BelongsToMany (many-to-many via pivot; `sync()` is transactional)
- **Global Query Scopes** — automatic WHERE constraints declared per model, bypassable per query
- **Pagination** — `paginate()` returns a `Paginator` with total, page, and navigation metadata
- **Bulk operations** — `insertOrIgnore()`, `upsert()`, `insertMany()`, `incrementWhere()`, `decrementWhere()`
- **Large datasets** — `chunk()` for batch processing, `cursor()` for generator-based streaming
- **Soft Deletes** — opt-in `SoftDeletable` trait; `destroy()` sets `deleted_at`, `restore()` reverts it (no-op if not trashed)
- **Authorization** — policy-based access control via `Actor`
- **Model Events** — `before:save`, `after:save`, `before:destroy`, `after:destroy`, `after:load`, `after:find`, and more; class-level (`Model::on()`) and instance-level (`$record->on()`)
- **Event Sourcing** — opt-in audit trail via `EventSourceable` trait
- **Schema migration** — `Schema::diff()` / `Schema::migrate()` without migration files
- **Computed fields** — virtual fields calculated at runtime, never persisted
- **N+1 Detection** — detects lazy-load loops during development
- **Framework agnostic** — adapters for Laravel 5–12, CodeIgniter 3–4, Phalcon 3–5, Symfony 4–7, Standalone PDO
- **Long-running process safe** — `Operation::clearLog()`, `N1Detector::fullReset()` for Octane/Swoole/RoadRunner

---

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

[](#installation)

```
composer require roulette/roulette
```

---

Quick Start
-----------

[](#quick-start)

```
use Roulette\Model;
use Roulette\Model\Prototype;

class User extends Model
{
    static protected ?Prototype $prototype = null;

    static function init(): void
    {
        static::prototype([
            'table'   => 'users',
            'primary' => 'id',
            'autoId'  => true,
            'fields'  => [
                ['name' => 'id',    'update' => false],
                ['name' => 'name',  'type' => 'string'],
                ['name' => 'email', 'type' => 'email'],
            ],
        ]);
    }
}
```

```
// Create — non-fillable fields in the array are silently ignored
$user = new User(['name' => 'Alice', 'email' => 'alice@example.com']);
$user->save();               // returns bool
$user->save(reload: false);  // skip post-save SELECT (faster for write-heavy paths)
$user->saveOrFail();         // throws ValidationException or QueryException on any failure

// Read
$user  = User::load('some-id');
$users = User::find(['active' => 1]);

// Update
$user->set('name', 'Alicia');
$user->save();

// Delete
$user->destroy();
```

---

Documentation
-------------

[](#documentation)

TopicDescription[Getting Started](docs/getting-started.md)Installation, DB connection, first model[Models](docs/model.md)Prototype config, CRUD, pagination, bulk ops, soft deletes[Fields](docs/fields.md)Types, lifecycle, validators, computed fields[Associations](docs/associations.md)HasOne, HasMany, BelongsTo, BelongsToMany[Query Builder](docs/query.md)Fluent queries, scopes, chunk, cursor, upsert[Collections](docs/collections.md)Collection, ManagedCollection, Store API reference[Authorization](docs/authorization.md)Actor, Policy, can/able — policy inverted-logic explained[Validators](docs/validators.md)All 27 built-in validators with parameters and error messages[Advanced](docs/advanced.md)Schema migration, soft deletes, event sourcing, N+1 detection[Tunel](docs/tunel.md)Framework adapters and writing a custom adapter---

License
-------

[](#license)

© Eko Dedy Purnomo. See [LICENSE](LICENSE) for details.

###  Health Score

50

—

FairBetter than 95% of packages

Maintenance94

Actively maintained with recent releases

Popularity10

Limited adoption so far

Community2

Small or concentrated contributor base

Maturity76

Established project with proven stability

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 ~860 days

Total

5

Last Release

33d ago

Major Versions

v1.x-dev → v2.x-dev2016-12-28

PHP version history (3 changes)v1.1.0PHP ^5.3.3 || ^7.0

v1.1.1PHP ^5.3.0

v2.0.0PHP &gt;=8.1

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/10175512?v=4)[Eko Dedy Purnomo](/maintainers/ekodedypurnomo)[@ekodedypurnomo](https://github.com/ekodedypurnomo)

---

Tags

phpvalidationdatabaseormmodelactive-recordquery builder

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[matchory/elasticsearch

The missing elasticsearch ORM for Laravel!

3061.7k](/packages/matchory-elasticsearch)[wayofdev/laravel-cycle-orm-adapter

🔥 A Laravel adapter for CycleORM, providing seamless integration of the Cycle DataMapper ORM for advanced database handling and object mapping in PHP applications.

3729.5k3](/packages/wayofdev-laravel-cycle-orm-adapter)[tommyknocker/pdo-database-class

Framework-agnostic PHP database library with unified API for MySQL, MariaDB, PostgreSQL, SQLite, MSSQL, and Oracle. Query Builder, caching, sharding, window functions, CTEs, JSON, migrations, ActiveRecord, CLI tools, AI-powered analysis. Zero external dependencies.

826.0k](/packages/tommyknocker-pdo-database-class)

PHPackages © 2026

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