PHPackages                             crocodicstudio/cbmodel - 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. crocodicstudio/cbmodel

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

crocodicstudio/cbmodel
======================

Boost your laravel database relation with model enhancement

v2.1.0(5y ago)213.7k1[1 issues](https://github.com/crocodic-studio/cb-model/issues)MITPHPPHP ~7.2|~7.3

Since Nov 17Pushed 5y ago2 watchersCompare

[ Source](https://github.com/crocodic-studio/cb-model)[ Packagist](https://packagist.org/packages/crocodicstudio/cbmodel)[ RSS](/packages/crocodicstudio-cbmodel/feed)WikiDiscussions master Synced 1w ago

READMEChangelog (10)Dependencies (3)Versions (29)Used By (0)

CB Laravel Model Repository
===========================

[](#cb-laravel-model-repository)

An alternative about laravel eloquent

This Package Is Deprecated
--------------------------

[](#this-package-is-deprecated)

Please use

### Requirement

[](#requirement)

Laravel 5.\* | 6.\* | 7.\*

### Install Command

[](#install-command)

`composer require crocodicstudio/cbmodel=^2.0`

### 1. Create a model

[](#1-create-a-model)

*Create a model from a table*
`php artisan create:model foo_bar_table`

*Create model for all tables*
`php artisan create:model`

*Create a model with other connection*
`php artisan create:model foo_bar_table --connection=con2`

I assume that you have a `books` table with the structure like bellow:

```
id (Integer) Primary Key
created_at (Timestamp)
name (Varchar) 255

```

It will auto create a new file at `/app/Models/Books.php` with the following file structure :

```

```

### 3. Using CB Model class that has a relation

[](#3-using-cb-model-class-that-has-a-relation)

I assume you have a table `categories` for book relation like bellow :

```
id (Integer) Primary Key
name (Varchar) 255

```

and your book structure to be like bellow:

```
id (Integer) Primary Key
created_at (Timestamp)
categories_id (Integer)
name (Varchar) 255

```

Now you have to create a model for `categories` table, you can following previous steps.

I assume that you have create a `categories` model, so make sure that now we have two files in the `/app/Models/`

```
/Books.php
/Categories.php

```

Open the Books model , and add this bellow method

```
    /**
    * @return Categories
    */
    public function category() {
        return $this->belongsTo("App\Models\Categories");
    }

    // or
    /**
    * @return Categories
    */
    public function category() {
        return Categories::find($this->categories_id);
    }
```

Then open the FooController

```

```

As you can see now we can get the category name by using `->category()->name` without any SQL Query or even Database Builder syntax. Also you can recursively go down to your relation with NO LIMIT.

### 4. How to Casting DB Builder Collection output to CB Model Class?

[](#4-how-to-casting-db-builder-collection-output-to-cb-model-class)

You can easily cast your simple database builder collection to cb model class.

```
$row = DB::table("books")->where("id",1)->first();

//Cast to CB Model
$model = new Books($row);

//And then you can use cb model normally
echo $model->name;
```

### 5. How to insert the data with CB Model

[](#5-how-to-insert-the-data-with-cb-model)

You can easily insert the data with method `->save()` like bellow:

```
$book = new Books();
$book->created_at = date("Y-m-d H:i:s"); //this created_at is a magic method you can ignore this
$book->name = "New Book";
$book->categories_id = 1;
$book->save();
```

Then if you want to get the last insert id you can do like bellow:

```
...
$book->save();
$lastInsertId = $book->id; // get the id from id property
...
```

### 5. How to update the data with CB Model

[](#5-how-to-update-the-data-with-cb-model)

You can easily update the data, just find it for first :

```
$book = Books::findById(1);
$book->name = "New Book";
$book->categories_id = 1;
$book->save();
```

### 5. How to delete the data?

[](#5-how-to-delete-the-data)

You can easily delete the data, just find it for first :

```
$book = Books::findById(1);
$book->delete();
```

or

```
Books::deleteById(1);
```

Model Method Available
----------------------

[](#model-method-available)

```
/**
* Find all data by specific condition.
*/
$result = FooBar::findAllBy($column, $value = null, $sorting_column = "id", $sorting_dir = "desc");
// or
$result = FooBar::findAllBy(['foo'=>1,'bar'=>2]);

/**
* Find all data without sorting
*/
$result = FooBar::findAll();

/**
* Count the records of table
*/
$result = FooBar::count();

/**
* Count the records with specific condition
*/
$result = FooBar::countBy($column, $value = null);
// or
$result = FooBar::countBy(['foo'=>1,'bar'=>2]);

/**
* Find all datas and ordering the data to descending
*/
$result = FooBar::findAllDesc($column = "id");
// or simply
$result = FooBar::latest();

/**
* Find all datas and ordering the data to ascending
*/
$result = FooBar::findAllAsc($column = "id");
// or simply
$result = FooBar::oldest();

/**
* Find/Fetch a record by a primary key value
*/
$result = FooBar::findById($id);
// or simply
$result = FooBar::find($id);

/**
* Create a custom query, and result laravel Query Builder collection
*/
$result = FooBar::table()->where("foo",1)->first();

/**
* Create a custom query and casting to model object
*/
$result = FooBar::query(function($query) {
    return $query->where("bar",1);
});

/**
* Create a custom list query and casting them to model objects
*/
$result = FooBar::queryList(function($query) {
    return $query->where("bar",1);
});

/**
* Find a record by a specific condition
*/
$result = Foobar::findBy($column, $value = null);
// or
$result = Foobar::findBy(['foo'=>1,'bar'=>2]);

/**
* To run the insert SQL Query
*/
$fooBar = new FooBar();
$fooBar->name = "Lorem ipsum";
$fooBar->save();

/**
* To bulk insert
*/
$data = [];
$foo = new FooBar();
$foo->name = "Lorem ipsum 1";
array_push($data, $foo);
$bar = new FooBar();
$bar->name = "Lorem ipsum 2";
array_push($data, $bar);
FooBar::bulkInsert($data);

/**
* To run the update SQL Query
*/
$fooBar = FooBar::findById($value);
$fooBar->name = "Lorem ipsum";
$fooBar->save();

/**
* To delete the record by a primary key value
*/
FooBar::deleteById($value);

/**
* To delete the record by a specific condition
*/
FooBar::deleteBy($column, $value = null);
// or
Foobar::deleteBy(['foo'=>1,'bar'=>2]);

/**
* To delete after you fetch the record
*/
$fooBar = FooBar::findById($value);
$fooBar->delete();
```

A One-To-Many Relationship
--------------------------

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

```
class Posts extends Model {
    // etc

    /**
    * @return App\Models\Comments[]
    */
    public function comments() {
        return $this->hasMany(Comments::class);
    }

    // or with full option
    /**
    * @return App\Models\Comments[]
    */
    public function comments() {
        return $this->hasMany(Comments::class, "foreign_key", "local_key", function($condition) {
            return $condition->where("status","Active");
        });
    }
}
```

A One-To-One Relationship
-------------------------

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

```
class Comments extends Model {
    // etc

    /**
    * @return App\Models\Posts
    */
    public function post() {
        return $this->belongsTo(Posts::class);
    }

    // or with full option
    /**
    * @return App\Models\Posts
    */
    public function post() {
        return $this->belongsTo(Posts::class, "foreign_key", "local_key");
    }
}
```

Other Useful
------------

[](#other-useful)

1. [CRUDBooster Laravel CRUD Generator](https://github.com/crocodic-studio/crudbooster)

###  Health Score

32

—

LowBetter than 69% of packages

Maintenance10

Infrequent updates — may be unmaintained

Popularity25

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity68

Established project with proven stability

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

Recently: every ~52 days

Total

28

Last Release

2034d ago

Major Versions

v1.19 → v2.02020-04-03

PHP version history (4 changes)v1.0PHP &gt;=5.6.0

v1.2PHP &gt;=7.2

v1.8PHP &gt;=5.6

v2.0PHP ~7.2|~7.3

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/45650601?v=4)[ferdevelop15](/maintainers/ferdevelop15)[@ferdevelop15](https://github.com/ferdevelop15)

---

Top Contributors

[![fherryfherry](https://avatars.githubusercontent.com/u/6733315?v=4)](https://github.com/fherryfherry "fherryfherry (20 commits)")

---

Tags

laravelmodelrepository

### Embed Badge

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

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

###  Alternatives

[spatie/laravel-medialibrary

Associate files with Eloquent models

6.2k45.4M681](/packages/spatie-laravel-medialibrary)[laravel/sail

Docker files for running a basic Laravel application.

1.9k212.4M1.4k](/packages/laravel-sail)[laravel/ai

The official AI SDK for Laravel.

1.1k4.6M281](/packages/laravel-ai)[laravel/mcp

Rapidly build MCP servers for your Laravel applications.

79227.1M206](/packages/laravel-mcp)[mike-bronner/laravel-model-caching

Automatic caching for Eloquent models.

2.4k161.4k1](/packages/mike-bronner-laravel-model-caching)[iazaran/smart-cache

Smart Cache is a caching optimization package designed to enhance the way your Laravel application handles data caching. It intelligently manages large data sets by compressing, chunking, or applying other optimization strategies to keep your application performant and efficient.

21114.2k](/packages/iazaran-smart-cache)

PHPackages © 2026

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