PHPackages                             jguyomard/silex-capsule-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. jguyomard/silex-capsule-eloquent

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

jguyomard/silex-capsule-eloquent
================================

Capsule/Eloquent Service Provider for Silex 2

v2.0.2(9y ago)619.7k31MITPHPPHP &gt;=5.5.9

Since Jun 26Pushed 9y ago3 watchersCompare

[ Source](https://github.com/jguyomard/silex-capsule-eloquent)[ Packagist](https://packagist.org/packages/jguyomard/silex-capsule-eloquent)[ RSS](/packages/jguyomard-silex-capsule-eloquent/feed)WikiDiscussions 2.0 Synced 3w ago

READMEChangelog (3)Dependencies (3)Versions (5)Used By (1)

Capsule (and Eloquent) Service Provider for Silex 2
===================================================

[](#capsule-and-eloquent-service-provider-for-silex-2)

[![Travis](https://camo.githubusercontent.com/852af43f0a941a5da08003dc456265693f60c2a168698811cda8c0b05c773aa7/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f6a6775796f6d6172642f73696c65782d63617073756c652d656c6f7175656e742e7376673f6d61784167653d31383030267374796c653d666c61742d737175617265)](https://travis-ci.org/jguyomard/silex-capsule-eloquent)[![StyleCI](https://camo.githubusercontent.com/15fa68a90ebc21a7b87360b72815a3daf7f590354c248af8151a41fd68ae0235/68747470733a2f2f7374796c6563692e696f2f7265706f732f35363337323830362f736869656c64)](https://styleci.io/repos/56372806)[![Packagist Release](https://camo.githubusercontent.com/fd103d00c93ff2e30e81ac80a920438161fd877e8339e2646918c83598da2e94/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6a6775796f6d6172642f73696c65782d63617073756c652d656c6f7175656e742e7376673f6d61784167653d31383030267374796c653d666c61742d737175617265)](https://packagist.org/packages/jguyomard/silex-capsule-eloquent)[![Licence](https://camo.githubusercontent.com/a36503c8e6a56cbe257e0cc252974f5989c0ab084dc4875cc839c448ff0f5546/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6a6775796f6d6172642f73696c65782d63617073756c652d656c6f7175656e742e7376673f6d61784167653d31383030267374796c653d666c61742d737175617265)](https://github.com/jguyomard/silex-capsule-eloquent/blob/master/LICENCE)

This is a Service Provider for [Silex](http://silex.sensiolabs.org/) 2.0 that integrates Laravel's [Fluent Query Builder](https://laravel.com/docs/5.2/queries) and [Eloquent ORM](https://laravel.com/docs/5.2/eloquent) via [Capsule](https://github.com/illuminate/database).

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

[](#installation)

Note: This Service Provider requires `silex/silex ~2.0`.

```
composer require jguyomard/silex-capsule-eloquent "~2.0"

```

Usage
-----

[](#usage)

This is a basic configuration with MySQL (Currently, Laravel supports MySQL, Postgres, SQLite and SQL Server):

```
$app = new Silex\Application();

$app->register(
    new \JG\Silex\Provider\CapsuleServiceProvider(),
    [
        'capsule.connections' => [
            'default' => [
                'driver'    => 'mysql',
                'host'      => 'localhost',
                'database'  => 'mydatabase',
                'username'  => 'root',
                'password'  => 'root',
            ]
        ]
    ]
);
```

This is a basic usage, using [Query Builder](https://laravel.com/docs/5.2/queries) or [Raw SQL Queries](https://laravel.com/docs/5.2/database#running-queries):

```
$app->get('/article/{id}', function(Application $app, $id)
{
    $article = Capsule::table('article')->where('id', $id)->get();

    // Rest of your code...
});

$app->get('/raw/{id}', function(Application $app, $id)
{
    $article = Capsule::select('SELECT * FROM article WHERE id = :id', [
        'id' => $id,
    ]);

    // Rest of your code...
});

$app->run();
```

You can also use [Eloquent Models](https://laravel.com/docs/5.2/eloquent):

```
class ArticleModel extends Model
{
    protected $table = 'article';

    protected $primaryKey = 'id';

    protected $fillable = [
        'title'
    ];

    // Rest of your code...
}

$app->get('/article/{id}', function(Application $app, $id)
{
    $article = ArticleModel::find($id);

    // Rest of your code...
});

$app->post('/article', function(Application $app)
{
    $article = ArticleModel::create([
        'title' => 'Foo'
    ]);

    // Rest of your code...
});

$app->run();
```

For further documentation on using the various database facilities this library provides, consult the [Laravel framework database documentation](https://laravel.com/docs/5.2/database).

Configuration
-------------

[](#configuration)

This is a complete configuration example, with multiple connections:

```
$app = new Silex\Application();

$app->register(
    new \JG\Silex\Provider\CapsuleServiceProvider(),
    [
        'capsule.connections' => [
            'default' => [
                'driver'    => 'mysql',
                'host'      => 'localhost',
                'port'      => 3306,
                'database'  => 'mydatabase',
                'username'  => 'root',
                'password'  => 'root',
                'charset'   => 'utf8',
                'collation' => 'utf8_unicode_ci',
                'prefix'    => '',
                'strict'    => false,
                'engine'    => null,
            ],
            'pgsql' => [
                'driver' => 'pgsql',
                'host'      => 'localhost',
                'port'      => 5432,
                'database'  => 'mydatabase',
                'username'  => 'root',
                'password'  => 'root',
                'charset'   => 'utf8',
                'prefix'    => '',
                'schema'    => 'public',
            ],
            'sqlite' => [
                'driver' => 'sqlite',
                'database'  => 'mydatabase',
                'prefix' => '',
            ],
        ],
        'capsule.options' => [
            'setAsGlobal'    => true,
            'bootEloquent'   => true,
            'enableQueryLog' => true,
        ],
    ]
);
```

Testing
-------

[](#testing)

To run the test suite, you need [PHPUnit](https://phpunit.de/):

```
phpunit

```

Credits
-------

[](#credits)

Inspired by [illuminate-database-silex-service-provider](https://github.com/mattkirwan/illuminate-database-silex-service-provider/) (for Silex 1.\*) and [saxulum-doctrine-mongodb-odm-provider@dev](https://github.com/saxulum/saxulum-doctrine-mongodb-odm-provider/tree/master) (Mongodb ODM for Silex 2.0.x-dev).

Issues
------

[](#issues)

If you have any problems with or questions about this Service Provider, please contact me through a [GitHub issue](https://github.com/jguyomard/silex-capsule-eloquent/issues). If the issue is related to Capsule itself please leave an issue on [Laravel official repository](https://github.com/laravel/framework/tree/5.2/src/Illuminate/Database).

Contributing
------------

[](#contributing)

You are invited to contribute new features, fixes or updates to this container, through a [Github Pull Request](https://github.com/jguyomard/silex-capsule-eloquent/pulls).

###  Health Score

35

—

LowBetter than 77% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity30

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity61

Established project with proven stability

 Bus Factor1

Top contributor holds 90% 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 ~53 days

Total

4

Last Release

3493d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1242207?v=4)[Julien Guyomard](/maintainers/jguyomard)[@jguyomard](https://github.com/jguyomard)

---

Top Contributors

[![jguyomard](https://avatars.githubusercontent.com/u/1242207?v=4)](https://github.com/jguyomard "jguyomard (18 commits)")[![matracine](https://avatars.githubusercontent.com/u/7325711?v=4)](https://github.com/matracine "matracine (1 commits)")[![Rakitin](https://avatars.githubusercontent.com/u/5819709?v=4)](https://github.com/Rakitin "Rakitin (1 commits)")

---

Tags

capsuleeloquentservice-providersilexlaravelsqleloquentquerycapsule

### Embed Badge

![Health badge](/badges/jguyomard-silex-capsule-eloquent/health.svg)

```
[![Health](https://phpackages.com/badges/jguyomard-silex-capsule-eloquent/health.svg)](https://phpackages.com/packages/jguyomard-silex-capsule-eloquent)
```

###  Alternatives

[mongodb/laravel-mongodb

A MongoDB based Eloquent model and Query builder for Laravel

7.1k8.0M88](/packages/mongodb-laravel-mongodb)[psalm/plugin-laravel

Psalm plugin for Laravel

3345.1M337](/packages/psalm-plugin-laravel)[watson/validating

Eloquent model validating trait.

9733.4M53](/packages/watson-validating)[rennokki/laravel-eloquent-query-cache

Adding cache on your Laravel Eloquent queries' results is now a breeze.

1.1k4.2M14](/packages/rennokki-laravel-eloquent-query-cache)[reedware/laravel-relation-joins

Adds the ability to join on a relationship by name.

2121.2M16](/packages/reedware-laravel-relation-joins)[dbout/wp-orm

WordPress ORM with Eloquent.

12910.2k1](/packages/dbout-wp-orm)

PHPackages © 2026

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