PHPackages                             laravel-orm/laravel-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. [Database &amp; ORM](/categories/database)
4. /
5. laravel-orm/laravel-orm

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

laravel-orm/laravel-orm
=======================

Describe your table fields in the model and let Laravel manage your migration for you

v0.2.0(7y ago)115GPL-3.0+PHPPHP &gt;=7.1.3

Since Nov 11Pushed 7y ago1 watchersCompare

[ Source](https://github.com/NastuzziSamy/laravel-orm)[ Packagist](https://packagist.org/packages/laravel-orm/laravel-orm)[ RSS](/packages/laravel-orm-laravel-orm/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependencies (6)Versions (6)Used By (0)

Laravel ORM
===========

[](#laravel-orm)

Describe your table fields in the model and let Laravel manage your migration for you.

Installation
============

[](#installation)

Simple installation
-------------------

[](#simple-installation)

`composer require laravel-orm/laravel-orm`

Usage
=====

[](#usage)

Laravel ORM allows you to automate multiple Laravel features as: - Describe perfectly all fields and relations for your model - Manage with the right type all your model attributes - Create easely your relations - Generate for you all your migrations (depending on your model description) - Create all scopes and helpers for building queries - Smartly add validations to your controller

Model description
-----------------

[](#model-description)

In a regular `User` model, it is hard to detect all the fields, the relations, without reading deeply the code or the migration file(s).

### Before

[](#before)

```
use Illuminate\Database\Eloquent\Model;

class User extends Model {
    protected $fillable = ['firstname', 'lastname', 'email', 'admin', 'group_id'];

    protected $casts = [
        'admin' => 'boolean',
    ];

    // By default, we want all except the admin boolean
    protected $hidden = ['admin'];

    public function group() {
        $this->belongsTo(Group::class);
    }
}
```

### After

[](#after)

```
use LaravelORM\Fields\{
    IncrementField, StringField, EmailField, BooleanField
};
use LaravelORM\CompositeFields\BelongsField;
use LaravelORM\Model;

class User extends Model {
    protected function __schema($schema, $fields) {
        $fields->id = IncrementField::class; // an increment field is by default unfillable
        $fields->firstname = StringField::class;
        $fields->lastname = StringField::class;
        $fields->email = EmailField::new()->unique();
        $fields->admin = BooleanField::new()->default(false)->hidden(); // Auto cast and hidden by default
        $fields->group = BelongsField::new()->to(Group::class);

        $schema->timestamps();

        $schema->unique([$fields->firstname, $fields->lastname]);
    }
}
```

Here we can now know all defined fields. The `group` relation is automatically defined.

Migrations
----------

[](#migrations)

### Before

[](#before-1)

Part of the migration file:

```
Schema::create('users', function (Blueprint $table) {
    $table->increments('id');
    $table->string('firstname');
    $table->string('lastname');
    $table->string('email')->unique();
    $table->integer('group_id')->unsigned(true);
    $table->timestamp('created_at')->nullable(true);
    $table->timestamp('updated_at')->nullable(true);

    $table->foreign('group_id')->references('id')->on('users');

    $table->unique('firstname', 'lastname');
});
```

### After

[](#after-1)

The previous file is generated via your model description.

Model interaction
-----------------

[](#model-interaction)

### Before

[](#before-2)

```
	// Get the first user
	$user = User::first();
	// Get with id 2
	User::where('id', 2)->first();
	// Get the email adress
	$user->email;
	// Set a bad format email adress
	$user->email = 'bad-email';
	// Set a good format email adress
	$user->email = 'good@email.orm';
	// Get user group relation
	$user->group();
	// Get user group
	$group = $user->group;
	// Search one user by group
	$user = $user->where('group_id', $group->id)->first();
	// Search all users by group
	$user = $user->where('group_id', $group->id)->get();
	// Search all users with a group id greater than specific one
	$user = $user->where('group_id', '>', $group->id)->get();
	// Get admin boolean (with casting)
	$user->admin; // true
	// Get admin boolean (without casting)
	$user->admin; // 1
```

### After

[](#after-2)

```
	// Get the first user
	$user = User::first();
	// Get with id 2
	$user2 = User::id(2);
	// Get the email adress
	$user->email;
	/* Set a bad format email adress
	 * In function of setttings:
	 * - Add automatically the domain (ex: '@email.orm')
	 * - Write the wrong email
	 * - Throw an exception telling the email adress is wrong
	 */
	$user->email = 'bad-email'; // => bad-email@email.orm or Exception
	// Set a good format email adress
	$user->email = 'good@email.orm';
	// Get user group relation
	$user->group();
	// Get user group
	$group = $user->group;
	// Search user by group
	$user = $user->group($group);
	// Search user by group
	$user = $user->whereGroup($group)->get();
	// Search all users with a group id greater than specific one
	$user = $user->whereGroup('>', $group)->get();
	// Get admin boolean (auto casting)
	$user->admin; // true
```

Validations
-----------

[](#validations)

### Not yet done

[](#not-yet-done)

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity50

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

Total

2

Last Release

2733d ago

### Community

Maintainers

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

---

Top Contributors

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

---

Tags

laravelmigrationdatabaseormmodeluuidfieldtablefieldsautometaautomaticvalidations

###  Code Quality

Code StylePHP\_CodeSniffer

### Embed Badge

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

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

###  Alternatives

[mongodb/laravel-mongodb

A MongoDB based Eloquent model and Query builder for Laravel

7.1k7.2M71](/packages/mongodb-laravel-mongodb)[dyrynda/laravel-model-uuid

This package allows you to easily work with UUIDs in your Laravel models.

4802.8M8](/packages/dyrynda-laravel-model-uuid)[mvanduijker/laravel-model-exists-rule

Validation rule to check if a model exists

22194.5k1](/packages/mvanduijker-laravel-model-exists-rule)[dragon-code/laravel-data-dumper

Adding data from certain tables when executing the `php artisan schema:dump` console command

3418.6k](/packages/dragon-code-laravel-data-dumper)

PHPackages © 2026

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