PHPackages                             arif-rh/ci4-dynamic-model - 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. arif-rh/ci4-dynamic-model

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

arif-rh/ci4-dynamic-model
=========================

Creating CodeIgniter 4 Model on-the-fly with Relationship Built-in Feature.

0.3.7(4y ago)1710.3k↓33.3%44MITPHPPHP &gt;=7.2

Since Apr 18Pushed 4y ago2 watchersCompare

[ Source](https://github.com/arif-rh/ci4-dynamic-model)[ Packagist](https://packagist.org/packages/arif-rh/ci4-dynamic-model)[ Docs](https://github.com/arif-rh/ci4-dynamic-model)[ RSS](/packages/arif-rh-ci4-dynamic-model/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (8)Versions (13)Used By (4)

DynaModel
=========

[](#dynamodel)

Dynamic Model for CodeIgniter 4
===============================

[](#dynamic-model-for-codeigniter-4)

[![Build Status](https://camo.githubusercontent.com/22699c9fcf31dc794eacd868488a29e95465b5733d5033cb128b84647a1d7797/68747470733a2f2f7472617669732d63692e636f6d2f617269662d72682f6369342d64796e616d69632d6d6f64656c2e7376673f6272616e63683d6d6173746572)](https://travis-ci.com/arif-rh/ci4-dynamic-model) [![Coverage Status](https://camo.githubusercontent.com/df2cd2a1b63d4447ba37ae3dc19087beb69659032472229339dc22c45e449f13/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f617269662d72682f6369342d64796e616d69632d6d6f64656c2f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/arif-rh/ci4-dynamic-model?branch=master)

Feature
-------

[](#feature)

- Dynamically Creating the Model on-the-fly
- Support One-to-One / Many-to-One relationship
- Support One-to-Many relationship
- Can Filter data based on child/related criteria
- Can set the order of One-to-Many relationship result based on child criteria

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

[](#installation)

`composer require arif-rh/ci4-dynamic-model`

Usage
-----

[](#usage)

### Simple

[](#simple)

```
    // creating postModel on-the-fly, just pass a table name
    $postModel = \Arifrh\DynaModel\DB::table('posts');

    // then you can use it, to get all posts
    $postModel->findAll();

```

### Many-to-One Relationship

[](#many-to-one-relationship)

```
    // assume that posts always belongs to one author using author_id
    $postModel->belongsTo('authors);

    // then you can grab author info along with posts
    $postModel->with('authors')->findAll();

    /**
    * by default, primary key of authors will be omit in the column result
    * because its value already exist in the foregin key of relationship
    *
    * if authors has same column name with posts, then it will be aliased with prefix "author_"
    * for example, both posts and authors has "rating" column, then it will become author_rating
    */

    // you can call only spesific column if you need, pass it on the second parameters in array
    $postModel->with('authors', ['name', 'rating'])->findAll();
    // will display all posts column, plus author name and author rating

    // you can filter posts based on author criteria
    $postModel->with('authors')->whereRelation('authors', ['status' => 'active'])->findAll();
    // will display all posts only from active authors

```

### One-to-Many Relationship

[](#one-to-many-relationship)

```
    $postModel->hasMany('comments');

    // this will return posts with all related comments
    $postModel->with('comments')->findAll();

    // you can also filter posts based on comments criteria
    $postModel->with('comments')->whereRelation('comments', ['status' => 'approved'])->findAll();
    // will display all posts with approved comments only

```

Testing
-------

[](#testing)

```
    composer test

    // or

    composer testdox

    // analyse code
    composer analyse

```

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity31

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

 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

Recently: every ~77 days

Total

12

Last Release

1805d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/b5e5b51452ac209ba31bade4dcabea32ebb599e0a49c778524e780aeb2b9bf0f?d=identicon)[arif-rh](/maintainers/arif-rh)

---

Top Contributors

[![arif-rh](https://avatars.githubusercontent.com/u/2386359?v=4)](https://github.com/arif-rh "arif-rh (63 commits)")

---

Tags

codeigniter4codeigniter4-modelcodeigniter4-relationshipmodelci4 modelcodeigniter modelcodeigniter4 modelcodeigniter4 relationshipci4 relationship model

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/arif-rh-ci4-dynamic-model/health.svg)

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

###  Alternatives

[mongodb/laravel-mongodb

A MongoDB based Eloquent model and Query builder for Laravel

7.1k7.2M71](/packages/mongodb-laravel-mongodb)[prettus/l5-repository

Laravel 5|6|7|8|9|10|11|12 - Repositories to the database layer

4.2k10.8M145](/packages/prettus-l5-repository)[spatie/laravel-translatable

A trait to make an Eloquent model hold translations

2.4k23.0M413](/packages/spatie-laravel-translatable)[spatie/eloquent-sortable

Sortable behaviour for eloquent models

1.5k22.9M268](/packages/spatie-eloquent-sortable)[venturecraft/revisionable

Keep a revision history for your models without thinking, created as a package for use with Laravel

2.6k6.6M51](/packages/venturecraft-revisionable)[tucker-eric/eloquentfilter

An Eloquent way to filter Eloquent Models

1.8k4.8M26](/packages/tucker-eric-eloquentfilter)

PHPackages © 2026

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