PHPackages                             jwh315/laravel-capsule-wrapper - 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. jwh315/laravel-capsule-wrapper

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

jwh315/laravel-capsule-wrapper
==============================

Use the Eloquent ORM outside of the Laravel Framework with an existing PDO database connection.

0.0.1(8y ago)731.2k↓50%5[1 PRs](https://github.com/jwh315/laravel-capsule-wrapper/pulls)MITPHP

Since Jun 19Pushed 8y ago2 watchersCompare

[ Source](https://github.com/jwh315/laravel-capsule-wrapper)[ Packagist](https://packagist.org/packages/jwh315/laravel-capsule-wrapper)[ RSS](/packages/jwh315-laravel-capsule-wrapper/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (2)Versions (2)Used By (0)

laravel-capsule-wrapper
=======================

[](#laravel-capsule-wrapper)

Use the Eloquent ORM outside of the Laravel Framework with an existing PDO database connection.

### disclaimer

[](#disclaimer)

This project is currently a proof of concept, without tests. I have manually tested it using a few standard Laravel operations with success, but I cannot currently vouch for its robustness in a real world PHP application.

One of the main issues I have not fully fleshed out is the database name parameter that you would normally pass into an eloquent connection. I have chosen to omit this parameter as my use case requires a database connection, with the ability to access multiple databases on the same connection. From my limited testing, this hasn't posed a problem, but I could be missing something.

Lastly, this only works for Mysql currently. This is done in `CapsuleManager\Wrapper\DatabaseManager::addDefaultConnection()`, theoretically you should be able to swap out any of the other `Illuminate\Database` connection classes as needed.

### installation

[](#installation)

```
composer require jwh315/laravel-capsule-wrapper

```

### usage

[](#usage)

This is pretty much the same as the usage instructions on the [Illuminate\\Database](https://github.com/illuminate/database)repository. It should be noted that I have not tested the `Schema Builder`

```
use CapsuleManager\Wrapper\Manager;
use Illuminate\Container\Container;
use Illuminate\Events\Dispatcher;

$dsn = "mysql:host=" . DBHOST;
$pdo = new \PDO($dsn, DBUSER, DBPASS);

$capsule = new Manager($pdo);

// Set the event dispatcher used by Eloquent models... (optional)
$capsule->setEventDispatcher(new Dispatcher(new Container));

// Make this Capsule instance available globally via static methods... (optional)
$capsule->setAsGlobal();

// Setup the Eloquent ORM... (optional; unless you've used setEventDispatcher())
$capsule->bootEloquent();

$t = $capsule::table('mysql.db')
			 ->where('Host', 'localhost')
			 ->get();

dd($t);

```

I also added a static accessor to encapsulate all of this boilerplate inside of the wrapper class, if you are going to use the defaults settings in the above example, this will also work.

```
use CapsuleManager\Wrapper\Manager as Capsule;

$dsn = "mysql:host=" . DBHOST;
$pdo = new \PDO($dsn, DBUSER, DBPASS);

$capsule = Capsule::init($pdo);

$t = $capsule::table('mysql.db')
			 ->where('Host', 'localhost')
			 ->get();

dd($t);

```

Using the Eloquent ORM

This is exactly the same as you would expect, except as mentioned above, I did not add a way to set the database name so you will have to set it explicitly

```
//initialize the capsule manager
use CapsuleManager\Wrapper\Manager as Capsule;

$dsn = "mysql:host=" . DBHOST;
$pdo = new \PDO($dsn, DBUSER, DBPASS);

$capsule = Capsule::init($pdo);

//user model example
use Illuminate\Database\Eloquent\Model;

class User extends Model
{
	//this needs to be set on all your models
	protected $table = 'test.users';
}

//using the user model
dd(User::all()->last()->login);

```

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity30

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity53

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

Unknown

Total

1

Last Release

3249d ago

### Community

Maintainers

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

---

Top Contributors

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

### Embed Badge

![Health badge](/badges/jwh315-laravel-capsule-wrapper/health.svg)

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

###  Alternatives

[mongodb/laravel-mongodb

A MongoDB based Eloquent model and Query builder for Laravel

7.1k7.2M71](/packages/mongodb-laravel-mongodb)[owen-it/laravel-auditing

Audit changes of your Eloquent models in Laravel

3.4k33.0M95](/packages/owen-it-laravel-auditing)[dyrynda/laravel-cascade-soft-deletes

Cascading deletes for Eloquent models that implement soft deletes

1.2k3.1M5](/packages/dyrynda-laravel-cascade-soft-deletes)[tightenco/parental

A simple eloquent trait that allows relationships to be accessed through child models.

1.5k1.8M5](/packages/tightenco-parental)[watson/validating

Eloquent model validating trait.

9723.3M47](/packages/watson-validating)[cybercog/laravel-ban

Laravel Ban simplify blocking and banning Eloquent models.

1.1k651.8k11](/packages/cybercog-laravel-ban)

PHPackages © 2026

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