PHPackages                             natilosir/orm - 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. natilosir/orm

ActiveLibrary

natilosir/orm
=============

A lightweight PHP ORM package

1.2.6(5mo ago)180↓100%3MITPHPPHP &gt;=8.0

Since Dec 13Pushed 5mo ago1 watchersCompare

[ Source](https://github.com/natilosir/ORM)[ Packagist](https://packagist.org/packages/natilosir/orm)[ RSS](/packages/natilosir-orm/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (6)DependenciesVersions (20)Used By (3)

Eloquent ORM in PHP
===================

[](#eloquent-orm-in-php)

This is a simple and elegant implementation of an ORM (Object-Relational Mapping) for PHP, designed to work with relational databases using fluent query building and Eloquent-style syntax.

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

[](#requirements)

- PHP &gt;= 8.0
- Composer

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

[](#installation)

You can install this ORM package via Composer:

```
composer require natilosir/ORM
```

Alternatively, you can clone the repository directly:

```
git clone https://github.com/natilosir/ORM
```

Example
-------

[](#example)

When using the DB class, make sure to include it with `use` .

```
use natilosir\orm\db;
```

### Select

[](#select)

- **Select** all data with chaining methods

```
$users = DB::Table('users')
    ->where('name', 'second')
    ->where('email', 'third')
    ->orderBy('id', 'max') // max = DESC, min = ASC
//  ->orderBy('max') // default value is id
    ->limit(3)
    ->get();

```

### Search

[](#search)

- **Search** with multiple conditions

```
$searchResults = DB::Table('users')
    ->search(['name' => 'Jane', 'email' => 'example.com'])
    ->orderBy('id', 'ASC') // max = DESC, min = ASC
    ->where('age', '>', 25)
    ->limit(3)
    ->get();

foreach ($searchResults as $result) {
    echo $result['id'].' - '.$result['name'].' - '.$result['email'].'';
}
```

### Count

[](#count)

- **Count** users with where condition

```
$userCount = DB::Table('users')
 // ->where('age', 25)  or search
    ->where('age', '>', 25)
    ->where('age', '>', 25, 'OR')
    ->where('age', '=', 25, 'and')
    ->count();
```

### orderBy

[](#orderby)

- Use the **orderBy** clause to sort users by email in ascending order with a limit

```
$orderedResults = DB::Table('users')
    ->where('name', 'John')
    ->where('name', 'jane')
    ->orderBy('id', 'deSC') // max = DESC, min = ASC
    ->limit(3)
    ->get();

foreach ($orderedResults as $result) {
    echo $result['id'].' - '.$result['name'].' - '.$result['email'].'';
}
```

### value

[](#value)

- Use the **value** function to add multiple columns dynamically with automatic numbering for duplicates.

```
$Price = DB::Table('extra')
    ->value('price','date')->get();
```

output

```
SELECT price, id FROM extra //...
```

### Insert array

[](#insert-array)

- **Insert** : Inserting new data with an **array**

```
$newUser = [
    'user'  => 'Jane.Doe',
    'name'  => 'Jane Doe',
    'email' => 'jane.doe@example.com'];
DB::Table('users')
    ->insert($newUser);
```

### Insert model

[](#insert-model)

- **Insert** new data with model instance

```
$data        = DB::Table('users');
$data->user  = 'first';
$data->name  = 'second';
$data->email = 'third';
$data->save();
```

### Update array

[](#update-array)

- **Update** data with an **array**

```
$updateData = [
    'user'  => 'Jane.Doe',
    'name'  => 'John Smith',
    'email' => 'john.smith@example.com'];
DB::Table('users')
    ->update(1, $updateData); // 1 is the ID and update({where}, {UpdateArray})

// Alternatively, update with multiple conditions:
DB::Table('users')
    ->update(['name' => 1, 'user' => 3], $updateData); // update({whereArray}, {UpdateArray})

//AND
DB::Table('users')
//  ->where(['name' => 1, 'user' => 2])
    ->where('name', 1) //AND oder methods in where
    ->update($updateData);
```

### Update model

[](#update-model)

- **Update**: Updating data with a model instance

```
$data        = DB::Table('users');
$data->user  = 'first';
$data->name  = 'second';
$data->email = 'third';
$data->save(1);  // 1 is the ID for the record to update $data->save('name' => 'Jane Doe');
```

### createOrFirst

[](#createorfirst)

```
DB::Table('users')->createOrFirst([ 'user_id' => $request->fromID, ],
[
'first_name' => $request->firstName,
'last_name'  => $request->lastName,
]);
```

### createOrUpdate

[](#createorupdate)

```
DB::Table('users')->createOrUpdate([ 'user_id' => $request->fromID, ],
[
'first_name' => $request->firstName,
'last_name'  => $request->lastName,
]);
```

### Delete

[](#delete)

- **Delete** data

```
DB::Table('users')
    ->delete(1); // 1 is the ID of the record to delete

// Alternatively, delete using conditions:
DB::Table('users')
    ->delete(['name' => 1, 'user' => 6]);

//AND
DB::Table('users')
    ->where(['name' => 1, 'user' => 5]) //AND oder methods in where
    ->delete();
```

### DISTINCT

[](#distinct)

- **Using DISTINCT in SQL**

```
$users = DB::Table('users')
    ->select('email')
    ->distinct()
    ->get();

foreach ($users as $user) {
    echo $user['email'].'';
}
```

### JSON

[](#json)

- **JSON**

```
$users = DB::Table('users')
    ->limit(3)
    ->json()
    ->get();

echo $users;
// [{"id":116,"name":"John Smith", ...
```

### sql

[](#sql)

- **show sql**

```
$price = DB::Table('extra')->WHERE('id', '>', '1')->value('price','date')
    ->sql();
```

output

```
SELECT price, id FROM extra WHERE id > :id
```

### query

[](#query)

- **Run a custom SQL query**

```
$customQueryResults = DB::query("SELECT * FROM users WHERE email LIKE '%example.com%' LIMIT 5");

foreach ($customQueryResults as $result) {
    echo $result['id'].' - '.$result['name'].' - '.$result['email'].'';
}
```

Model
=====

[](#model)

- **Configuration**The model is configured to use the `users` table by default. You can change this by modifying the `$table` property:

```
class User extends Model {
    protected static string $table = 'users';
}
```

- **Use**

```
User::createOrFirst([ 'user_id' => $request->fromID, ], [
'first_name' => $request->firstName,
'last_name'  => $request->lastName,
]);
// OR
$Result = User::where('user_id', $fromID)->first();
```

###  Health Score

40

—

FairBetter than 88% of packages

Maintenance73

Regular maintenance activity

Popularity13

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity52

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

Recently: every ~31 days

Total

19

Last Release

154d ago

PHP version history (2 changes)v1.0.0PHP &gt;=5.6

1.2PHP &gt;=8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/ab074f478dbfd74f8f693edecac575b69c1e42087aaa44343cc1b45c43c23059?d=identicon)[natilosir](/maintainers/natilosir)

---

Top Contributors

[![natilosir](https://avatars.githubusercontent.com/u/182812192?v=4)](https://github.com/natilosir "natilosir (29 commits)")

### Embed Badge

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

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

PHPackages © 2026

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