PHPackages                             andikaryanto11/ci4orm - 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. andikaryanto11/ci4orm

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

andikaryanto11/ci4orm
=====================

ORM Database mapping for Codeigniter 4

v0.0.9(4y ago)02802MITPHPPHP ^7.4

Since May 23Pushed 4y ago1 watchersCompare

[ Source](https://github.com/andikaryanto11/Ci4Orm)[ Packagist](https://packagist.org/packages/andikaryanto11/ci4orm)[ Docs](https://packagist.org/packages/andikaryanto11/ciorm)[ RSS](/packages/andikaryanto11-ci4orm/feed)WikiDiscussions development Synced 2d ago

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

Codeigniter 4 ORM
=================

[](#codeigniter-4-orm)

This package is created to map your database to entity / Class you make. Inspired by .NET Enitity Framwork.

Rules
=====

[](#rules)

Create class then Extends to this Eloquent

Install
=======

[](#install)

```
composer require andikaryanto11/ci4orm

```

Props
=====

[](#props)

- protected $table = "your\_table\_name" is mandatory property you have to set
- static $primaryKey = "your\_primary\_key\_field\_name" is mandatory property you have to set

    ```
    use AndikAryanto11\Eloquent;
    class MyEloquent extends Eloquent{

      public $FieldInTable;
      public $AnotherFieldInTable;

      protected $table = "MyTable";
      static $primaryKey = "MyPKfield";

      public function __construct()
      {
          $db = \Config\Database::connect();
          parent::__construct($db);
      }
    }

    ```
- protected $hideFieldValue = \[ \] , when you put field in this array the field will be unset when you fetch data from eloquent

    ```
    protected $hideFieldValue = [ 'Password' ]

    ```
- protected $cast = \[\], when you put field in this array the field will be casted to specific datatype when you fetch data from eloquent. available cast datatype will be : - integer - boolean - decimal:2 -&gt; 2 will be decimal digit - datetime:Y-m-d -&gt; Y-m-d will be formatted date - string

    ```
    protected $cast = [
      'Id'             => 'integer',
      'IsLoggedIn'     => 'boolean',
      'Paid'           => 'decimal:2',
      'Created'        => 'datetime:Y-m-d',
    ];

    ```

Method
======

[](#method)

- find($id)

    Will get data from your table with "id"

    ```
    Entity::find(1);
    // return your Entity Object with "Id" = 1 or null

    ```
- findOrNew($id)

    Will get data from your table with "id" or new object if null

    ```
    Enitity::findOrNew(1);
    //return your Entity Object with "Id" = 1 or New object if no data found

    ```
- findOrFail($id)

    Will get data from your table with "id" or new object if null

    ```
    Enitity::findOrFail(1);
    //return your Entity Object with "Id" = 1 or throw an error

    ```
- findOne(array $params)

    Will get data from your table in first row from result

    ```
    $params = [
      "where" => [
        "colum_name" => "some_value"
      ]
    ];

    Entity::findOne($params);
    //$params is nullable
    //return first row of results or null;

    ```
- findOneOrNew(array $params)

    Will get data from your table in first row from result or new object

    ```
    $params = [
      "where" => [
        "colum_name" => "some_value"
      ]
    ];

    Entity::findOneOrNew($params);
    //$params is nullable
    //return first row of results or new object;

    ```
- findOneOrFail(array $params)

    Will get data from your table in first row from result or throw error

    ```
    $params = [
      "where" => [
        "colum_name" => "some_value"
      ]
    ];

    Entity::findOneOrFail($params);
    //$params is nullable
    //return first row of results or throw error;

    ```
- findAll(array $params)

    Will get data from your table or null

    ```
    $params = [
      "where" => [
        "colum_name" => "some_value"
      ]
    ];

    Entity::findAll($params);
    //$params is nullable
    //return first row of results or null;

    ```
- findAllOrFail(array $params)

    Will get data from your table or throw error

    ```
    $params = [
      "where" => [
        "colum_name" => "some_value"
      ]
    ];

    Entity::findAll($params);
    //$params is nullable
    //return first row of results or throw error;

    ```
- beforeSave()

    Will be executed before save method. Override this method if you wanna do something before save.
- save()

    Will store your data to table or update your data, If your "primary\_key" entity is null then it will save data otherwise will update;

    ```
    $ent = new Entity();
    $ent->Name = "whatever";
    $ent->save();
    //insert

    $ent = Entity::find(1);
    $ent->Name = "whatever";
    $ent->save();
    //update

    ```
- hasOne(string $relatedEloquent, string $foreignKey)

    Will get your related table data parent or null

    ```
    $ent = Entity::find(1);
    $parent = $ent->hasOne("Your\EntityNamespace\EntityName", "$ent foregin_key_name");
    // $parent is data parent of your related table;

    ```
- hasOneOrNew(string $relatedEloquent, string $foreignKey)

    Will get your related table data parent or new object

    ```
    $ent = Entity::find(1);
    $parent = $ent->hasOneOrNew("Your\EntityNamespace\EntityName", "$ent foregin_key_name");
    // $parent is data parent of your related table or new object;

    ```
- hasOneOrFail(string $relatedEloquent, string $foreignKey)

    Will get your related table data parent or throw error

    ```
    $ent = Entity::find(1);
    $parent = $ent->hasOneOrNew("Your\EntityNamespace\EntityName", "$ent foregin_key_name");
    // $parent is data parent of your related table or new object;

    ```
- hasMany(string $relatedEloquent, string $foreignKey, array $params)

    Will get your related table data child or null

    ```
    $ent = Entity::find(1);

    $params = [
      "where" => [
        "colum_name" => "some_value"
      ]
    ];

    $child = $ent->hasMany("Your\EntityNamespace\EntityName", "$ent foregin_key_name", $params);
    //$params is nullable
    // $child is data child of your related table or new object;

    ```
- hasManyOrFail(string $relatedEloquent, string $foreignKey, array $params)

    Will get your related table data child or throw error

    ```
    $ent = Entity::find(1);

    $params = [
      "where" => [
        "colum_name" => "some_value"
      ]
    ];

    $child = $ent->hasMany("Your\EntityNamespace\EntityName", "$ent foregin_key_name", $params);
    //$params is nullable
    // $child is data parent of your related table or new object;

    ```
- hasFirst(string $relatedEloquent, string $foreignKey, $params = \[\]) Will get first data

    ```
    $ent = Entity::find(1);

    $params = [
      "where" => [
        "colum_name" => "some_value"
      ]
    ];

    $child = $ent->hasFirst("Your\EntityNamespace\EntityName", "$ent foregin_key_name", $params);
    //$params is nullable
    // $child is data parent of your related table or new object;

    ```
- collect(array $filter = \[\]) Will return EloquentList, open in vendor folder to see available method.

    ```
    $obj = Entity::collect()

    ```
- paging($filter = \[\], $page = 1, $size = 6, $showedPage = 5, $queryParams = \[\]) Will return array of data and othe property

    ```
    $obj = Entity::paging([], 1, 6, 5, []);

    ```
- datatables(array $filter = \[\], boolean $returnEntity = true, boolean $useIndex = true) Will return EloquentDatatables, open vendor folder to see available method.

    ```
    $obj = Entity::datatables([], true, true);

    ```

Params ($params)
================

[](#params-params)

General for $params that's used to filter data

```
    $params = [
      "join" => [
        "table_name" => [[
            "key" => "table_name.key = table_name.key",
            "type" => "LEFT" || "RIGHT" //optional
        ]]
      ],
      "you can add more key params below, 'where', 'whereIn', etc"
    ];

    $params = [
      "where" => [
        "colum_name" => "some_value"
      ]
    ];

    $params = [
      "orWhere" => [
        "colum_name" => "some_value"
      ]
    ];

    $params = [
      "whereIn" => [
        "colum_name" => ["some_value", "other_value"]
      ]
    ];

    $params = [
      "orWhereIn" => [
        "colum_name" => ["some_value", "other_value"]
      ]
    ];

    $params = [
      "whereNotIn" => [
        "colum_name" => ["some_value", "other_value"]
      ]
    ];

    $params = [
      "like" => [
        "colum_name" => "some_value"
      ]
    ];

    $params = [
      "orLike" => [
        "colum_name" => "some_value"
      ]
    ];

    $params = [
      "orLike" => [
        "colum_name" => "some_value"
      ]
    ];

    $params = [
      "order" => [
        "colum_name" => "ASC",
        "colum_name" => "DESC"
      ]
    ];

    $params = [
      "limit" => [
        "page" => "ASC",
        "size" => "DESC"
      ]
    ];

```

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 91.8% 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 ~21 days

Recently: every ~13 days

Total

7

Last Release

1686d ago

PHP version history (2 changes)v0.0.3PHP ^7.2

v0.0.5PHP ^7.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/950802ff655f8097071a44b580b103bbfacf5b7d4de01acb8c24cc25a9055936?d=identicon)[andikaryanto11](/maintainers/andikaryanto11)

---

Top Contributors

[![andikaryanto](https://avatars.githubusercontent.com/u/41881539?v=4)](https://github.com/andikaryanto "andikaryanto (67 commits)")[![andikaryanto11](https://avatars.githubusercontent.com/u/42728084?v=4)](https://github.com/andikaryanto11 "andikaryanto11 (6 commits)")

---

Tags

databaseormcodeignitereloquentcodeigniter4

### Embed Badge

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

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

###  Alternatives

[tatter/relations

Entity relationships for CodeIgniter 4

9022.3k1](/packages/tatter-relations)[dbout/wp-orm

WordPress ORM with Eloquent.

1279.6k1](/packages/dbout-wp-orm)[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.

3516.7k3](/packages/wayofdev-laravel-cycle-orm-adapter)[tatter/schemas

Database schema management, for CodeIgniter 4

2328.5k1](/packages/tatter-schemas)[expressodev/laravel-codeigniter-db

Integration layer allowing use of the Laravel database library in CodeIgniter applications

314.0k1](/packages/expressodev-laravel-codeigniter-db)[andreagroferreira/laravel-sync-tracker

A Laravel package for tracking entity synchronization status between systems

113.0k](/packages/andreagroferreira-laravel-sync-tracker)

PHPackages © 2026

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