PHPackages                             envor/laravel-managed-databases - 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. envor/laravel-managed-databases

Abandoned → [envor/laravel-datastores](/?search=envor%2Flaravel-datastores)Library[Database &amp; ORM](/categories/database)

envor/laravel-managed-databases
===============================

A small package for managing multiple databases and their connections at runtime using laravel tools.

v1.1.4(2y ago)130[2 PRs](https://github.com/envor/laravel-managed-databases/pulls)MITPHPPHP ^8.2

Since Feb 8Pushed 1y ago1 watchersCompare

[ Source](https://github.com/envor/laravel-managed-databases)[ Packagist](https://packagist.org/packages/envor/laravel-managed-databases)[ Docs](https://github.com/envor/laravel-managed-databases)[ GitHub Sponsors](https://github.com/envor)[ RSS](/packages/envor-laravel-managed-databases/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (7)Dependencies (11)Versions (13)Used By (0)

A small package for managing multiple databases and their connections at runtime using laravel tools
----------------------------------------------------------------------------------------------------

[](#a-small-package-for-managing-multiple-databases-and-their-connections-at-runtime-using-laravel-tools)

[![Latest Version on Packagist](https://camo.githubusercontent.com/61ea65e0e4b8898497fb281fc2b6bbb8ec56410978ef2674729314cdf8b108ed/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f656e766f722f6c61726176656c2d6d616e616765642d6461746162617365732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/envor/laravel-managed-databases)[![GitHub Tests Action Status](https://camo.githubusercontent.com/e730538c2eb55f41e52fb5b93d2fb28c78faf72282ed54325ae30fa6ba5f0613/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f656e766f722f6c61726176656c2d6d616e616765642d6461746162617365732f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/envor/laravel-managed-databases/actions?query=workflow%3Arun-tests+branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/3b8c1fc6b88acbfc64c6cbb7f45c25ac2215e8317c274d9ebec6b0b495377673/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f656e766f722f6c61726176656c2d6d616e616765642d6461746162617365732f6669782d7068702d636f64652d7374796c652d6973737565732e796d6c3f6272616e63683d6d61696e266c6162656c3d636f64652532307374796c65267374796c653d666c61742d737175617265)](https://github.com/envor/laravel-managed-databases/actions?query=workflow%3A%22Fix+PHP+code+style+issues%22+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/d8f0f9c3a4126e7d1667f4a0c8c72341a68471c741aa2e465a1e0fdc2e24898e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f656e766f722f6c61726176656c2d6d616e616765642d6461746162617365732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/envor/laravel-managed-databases)

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

[](#installation)

You can install the package via composer:

```
composer require envor/laravel-managed-databases
```

Usage
-----

[](#usage)

[createDatabase()](#manageddatabasescreatedatabase)
[runOnDatabase()](#manageddatabasesrunondatabase)
[configureDatabase()](#manageddatabasesconfiguredatabase)

### \#`ManagedDatabases::createDatabase()`

[](#manageddatabasescreatedatabase)

The `createDatabase()` method will

- Cache the current default database connection config
- Set the connection to the `$managerConnection`
- Purge the connection and reconnect
- Create the physical database
- Purge the connection
- Restore original default connection
- Purge and reconnect

Tip

The `$managerConnection` must exist and be a configured database connection.
This package creates a few defaults: `manager_sqlite`, `manager_mysql` and `manager_mariadb`.
They are bootstrapped into memory by cloning the default configs for `sqlite`, `mysql` and `mariadb`.

```
use Envor\ManagedDatabases\ManagedDatabases;

$managerConnection = 'manager_sqlite';
$name = 'database'

ManagedDatabases::createDatabase($name, $managerConnection);

// database
```

### \#`ManagedDatabases::runOnDatabase()`

[](#manageddatabasesrunondatabase)

The `runOnDatabase()` method will connect the given `$database` using a new connection created with the credentials and options from the given `$managerConnection`, execute the given `$callback`, then finally, restore the original default database connection.

- Cache the current default database connection config
- Create a new connection config for the database by cloning the `$managerConnection` config
- Set the database as default and connect to it
- Run the given callback
- Purge the connection
- Restore original default connection
- Purge and reconnect

```
use Envor\ManagedDatabases\ManagedDatabases;

ManagedDatabases::runOnDatabase(
    $database = 'database',
    $callback = fn() => Artisan::call('migrate', ['--force' => true]),
    $managerConnection = 'manager_sqlite'
);
```

The package also includes an `artisan` wrapper for the `runOnDatabase()` method called `managed-databases:run`. The simplest and most harmless way to check it out is by pasting the following command into your terminal:

```
php artisan managed-databases:run "migrate:fresh --seed" --database=":memory:" --managerConnection="sqlite"
```

This will run your migrations and seeders harmlessly against an in-memory sqlite database. A great way to quickly check if they can run without errors.

### \#`ManagedDatabases::configureDatabase()`

[](#manageddatabasesconfiguredatabase)

The `configureDatabase()` method will set the given database as the default on on a brand new connection modeled after the given `$managerConnection`

```
use Envor\ManagedDatabases\ManagedDatabases;

ManagedDatabases::createDatabase('database2', 'sqlite');

ManagedDatabases::useDatabase('database2', 'sqlite');

config('database.default');

// database2

config('database.connections.database2')

// [
//     "driver" => "sqlite",
//     "url" => null,
//     "database" => "/home/forge/mysite.com/storage/app/managed_database2.sqlite",
//     "prefix" => "",
//     "foreign_key_constraints" => true,
// ]
```

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

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

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [inmanturbo](https://github.com/envor)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance28

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity61

Established project with proven stability

 Bus Factor1

Top contributor holds 95.7% 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 ~1 days

Total

9

Last Release

816d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/0261babef618b8fb3bfcea84376ed5e71e7169586eb8de63a6550c2e7ea653a6?d=identicon)[inmanturbo](/maintainers/inmanturbo)

---

Top Contributors

[![inmanturbo](https://avatars.githubusercontent.com/u/47095624?v=4)](https://github.com/inmanturbo "inmanturbo (45 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (1 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (1 commits)")

---

Tags

databasedatabase-managementlaravellaravelenvorlaravel-managed-databases

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/envor-laravel-managed-databases/health.svg)

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

###  Alternatives

[dyrynda/laravel-model-uuid

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

4802.8M8](/packages/dyrynda-laravel-model-uuid)[spatie/laravel-model-flags

Add flags to Eloquent models

4301.1M1](/packages/spatie-laravel-model-flags)[clickbar/laravel-magellan

This package provides functionality for working with the postgis extension in Laravel.

423715.4k1](/packages/clickbar-laravel-magellan)[spatie/laravel-sql-commenter

Add comments to SQL queries made by Laravel

1931.4M1](/packages/spatie-laravel-sql-commenter)[spatie/laravel-deleted-models

Automatically copy deleted records to a separate table

409109.8k4](/packages/spatie-laravel-deleted-models)[wnx/laravel-backup-restore

A package to restore database backups made with spatie/laravel-backup.

203330.1k2](/packages/wnx-laravel-backup-restore)

PHPackages © 2026

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