PHPackages                             corephp/slim-eloquent - 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. corephp/slim-eloquent

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

corephp/slim-eloquent
=====================

Wrapper dependency for eloquent database

0.0.2.0(7y ago)16Apache-2.0PHP

Since Mar 1Pushed 7y ago1 watchersCompare

[ Source](https://github.com/danteay/corephp-slim-elquent)[ Packagist](https://packagist.org/packages/corephp/slim-eloquent)[ RSS](/packages/corephp-slim-eloquent/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (2)Dependencies (3)Versions (3)Used By (0)

Eloquent dependency wrapper for Slim 3
======================================

[](#eloquent-dependency-wrapper-for-slim-3)

This is a simple wrapper of Eloquent ORM for Slim 3. It provides a Parser class to generate connections option from a standard database URL of PostgresSQL, MySQL or SQLite databases.

Dependencies
------------

[](#dependencies)

- [illuminate/database](https://packagist.org/packages/illuminate/database)

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

[](#installation)

You can use the [slimcmd](https://packagist.org/packages/corephp/slim-cmd) tool to install this dependency:

```
slimcmd dependency:add eloquent
```

Or you can setup manually:

```
composer require corephp/slim-eloquent
```

Allowed Database URLs
---------------------

[](#allowed-database-urls)

Te allowed formats of database connections are:

### MySQL

[](#mysql)

```
mysql://user:password@host:post/database
```

### PostgreSQL

[](#postgresql)

```
postgres://user:password@host:post/database
```

### SQLite

[](#sqlite)

```
sqlite://pato/to.database
```

Using Parser class
------------------

[](#using-parser-class)

The Parser class has 3 available methods to generate conection opctions for Eloquent:

- **parseConnection**: Parse connection strings for MySQL, PostgreSQL and SQLite connections.
- **parseGeneral**: Parse connections for MySQL and PostgreSQL only.
- **parseSqlite**: Parse connections for SQLite only.

The `parseConnection` and the `parseGeneral` function generates a configuration array as it shown below when pass a PostgreSQL or MySQL connection:

```
$options = [
    'driver'    => 'mysql|pgsql|sqlite',
    'host'      => 'host',
    'port'      => 3306,
    'database'  => 'database',
    'username'  => 'user',
    'password'  => 'pass',
    'charset'   => 'utf8mb4',
    'collation' => 'utf8mb4_unicode_ci',
];
```

The `parseConnection` and the `parseSqlite` function generates a configuration array as shown below when pass a SQLite connection.

```
$options = [
    'driver' => 'sqlite',
    'database' => '/path/to.database',
    'foreign_key_constraints' => true,
    'charset' => 'utf8mb4',
    'collation' => 'utf8mb4_unicode_ci',
];
```

### Examples

[](#examples)

```
use CorePHP\Slim\Dependency\Database\Parser;

$settings = [
    // ...
    "database" => Parser::parseConnection(
        getenv('DATABASE_URL')
    )
    // ...
];
```

Eloquent Wrapper
----------------

[](#eloquent-wrapper)

This class allows you to create the main connection to embed as dependency on Slim. You can generate a `database.php` file your dependencies section with the code below:

```
use CorePHP\Slim\Dependency\Database\Eloquent;

return function ($container) {
    $settings = $container->get('eloquent');

    $eloquent = new Eloquent();
    $eloquent->addConnection($settings);

    return $eloquent->getManager();
};
```

This generates the main connection and boot Eloquent to use the models. Also you can setup a read and write configuration with diferent databases.

```
use CorePHP\Slim\Dependency\Database\Eloquent;

return function ($container) {
    $eloquent = new Eloquent();
    $eloquent->addConnection($container['database'], 'default', 'r'); // read
    $eloquent->addConnection($container['database2'], 'default', 'w'); // write

    return $eloquent->getManager();
}
```

Base Model class
----------------

[](#base-model-class)

This packages provides a predefined base model class that brings you the most basic configuration of Models that you need and you can use it as shown below:

```
use CorePHP\Slim\Dependency\Database\Model;

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

The Model class has 2 preconfigured functions:

- **getDateFormat**: Has the date format definition as 'Y-m-d H:i:s'
- **scopePagination**: Scope that can be aded at the end of a chain of query filters to generate paginated sections of a single query. This scope has 3 parameters: $limit, $page and $links in that order.
    - `$limit`: Is the number of elements by page that will be retrived by the query.
    - `$page`: Page that will be retrived. I you set a number lower than 1, you will always have the page 1, and if you set a number greater than the total of pages, you will always have the last page posible.
    - `$links`: this is a boolean parameter, if you set as true, this generates an extra key on the resultant array named *links* that will have the pagination sections in an array like this: `[1, 2, 3, 4, 5, 6, '...', 100]`. this can Helpyou to generate a custom pagination for your datatables.

### Pagination example

[](#pagination-example)

```
$items = User::where('name', 'like', '%Jhon%')
    ->pagination(10, 1, true);

// The content of items variable will be:
//
// [
//    "data" => [ ... ]
//    "pages" => [
//      "limit" => 10,
//      "pages" => 100    /* depending of the total elemtns */
//      "total" => 1000   /* total elemtns of the query */
//      "page" => 1,
//      "links" => [ 1, 2, 3, 4, 5, 6, '...', 100 ]
//    ]
// ]
```

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity51

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

2628d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/28ea51f1e7e9dfd8b9a871dcd586cc946b6cd8a870ff047b04336db9bf772d0a?d=identicon)[danteay](/maintainers/danteay)

---

Top Contributors

[![danteay](https://avatars.githubusercontent.com/u/9085902?v=4)](https://github.com/danteay "danteay (5 commits)")

---

Tags

composerdatabaseeloquentormphp7slim-3slim-framework

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/corephp-slim-eloquent/health.svg)

```
[![Health](https://phpackages.com/badges/corephp-slim-eloquent/health.svg)](https://phpackages.com/packages/corephp-slim-eloquent)
```

###  Alternatives

[owen-it/laravel-auditing

Audit changes of your Eloquent models in Laravel

3.4k33.0M95](/packages/owen-it-laravel-auditing)[staudenmeir/eloquent-json-relations

Laravel Eloquent relationships with JSON keys

1.1k5.8M24](/packages/staudenmeir-eloquent-json-relations)[bavix/laravel-wallet

It's easy to work with a virtual wallet.

1.3k1.1M11](/packages/bavix-laravel-wallet)[dragon-code/migrate-db

Easy data transfer from one database to another

15717.4k](/packages/dragon-code-migrate-db)[gearbox-solutions/eloquent-filemaker

A package for getting FileMaker records as Eloquent models in Laravel

6454.8k2](/packages/gearbox-solutions-eloquent-filemaker)[cybercog/laravel-ownership

Laravel Ownership simplify management of Eloquent model's owner.

9126.6k3](/packages/cybercog-laravel-ownership)

PHPackages © 2026

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