PHPackages                             envor/laravel-database-manager - 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-database-manager

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

envor/laravel-database-manager
==============================

A small library for managing databases.

v2.0.2(2y ago)124[2 PRs](https://github.com/envor/laravel-database-manager/pulls)MITPHPPHP ^8.1

Since Mar 3Pushed 2y agoCompare

[ Source](https://github.com/envor/laravel-database-manager)[ Packagist](https://packagist.org/packages/envor/laravel-database-manager)[ Docs](https://github.com/envor/laravel-database-manager)[ RSS](/packages/envor-laravel-database-manager/feed)WikiDiscussions main Synced yesterday

READMEChangelog (10)Dependencies (10)Versions (16)Used By (0)

Abondoned! Use  instead
=======================================================================

[](#abondoned-use-httpsgithubcomenvorlaravel-schema-macros-instead)

A small library for managing databases
======================================

[](#a-small-library-for-managing-databases)

Create and delete `mysql` and `sqlite` databases. Soft deletes, or "recycles" databases by default. Also it can clean up old recycled databases.

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

[](#installation)

You can install the package via composer:

```
composer require envor/laravel-database-manager
```

Warning

If you are using laravel 10, you will have to manually install doctrine/dbal
doctrine/dbal is not a requirement for Laravel 11

```
composer require doctrine/dbal
```

You can publish the config file with:

```
php artisan vendor:publish --tag="database-manager-config"
```

This is the contents of the published config file:

```
// config for Envor/DatabaseManager
return [
    /***
     * The disk where the sqlite database files will be stored.
     */
    'sqlite_disk' => 'local',

    /***
     * Available drivers that can be managed.
     */
    'managers' => [
        'sqlite' => \Envor\DatabaseManager\SQLiteDatabaseManager::class,
        'mysql' => \Envor\DatabaseManager\MySQLDatabaseManager::class,
    ]
];
```

Usage
-----

[](#usage)

### Faking

[](#faking)

This package tests things like creating and deleting physical databases so that you don't have to. You simply call `DatabaseManager::fake()` then test your application's feature logic (validation, etc)

```
// controller
public function store(Request $request)
{
    $this->validate($request->all());

    $databaseManager = (new Envor\DatabaseManager)
        ->manage($request->database_driver)
        ->createDatabase($request->database_name);

    if($databaseManager){
        $request->user()->databases()->create([
            'name' => $request->database_name,
            'driver' => $request->database_driver,
        ]);
    }
}
```

```
    // test
    public function test_it_can_create_a_database(): void
    {
        $this->actingAs($user = User::factory()->create());

        Envor\DatabaseManager\Facades\DatabaseManager::fake();

        $this->post(route('database.create'), [
            'database_driver' => 'sqlite',
            'database_name' => 'test_database',
        ]);

        $this->assertDatabaseHas('databases', [
            'user_id' => $user->id,
            'driver' => 'sqlite',
            'name' => 'test_database',
        ]);
    }
```

### SQLite

[](#sqlite)

Creates an sqlite database at `storage/app/my-new-database.sqlite`

```
$databaseManager = (new Envor\DatabaseManager)
    ->manage('sqlite')
    ->createDatabase('my-new-database');
```

Soft deletes the database and moves it to `storage/app/.trash/2023/03/02/07_04_38_my-new-database.sqlite`:

> The package appends the .sqlite file extension on its own, and expects managed sqlite database files to have the extension

```
echo now()->format('Y/m/d_h_i_s_');
// 2023/3/2/7_04_38_
$databaseManager->deleteDatabase(
    databaseName: 'my-new-database',
    deletedAt: now(), // optional: defaults to now() (Carbon date)
);
```

Erases the database permanently from disk:

```
// erase the database permanently from disk
$databaseManager->eraseDatabase('.trash/2023/03/02/07_04_38_my-new-database');
```

Erases all the database files in the .trash folder with mtime more than one day old:

```
$databaseManager->cleanupOldDatabases(
    daysOld: 1, // optional, defaults to one
);
```

### MYSQL

[](#mysql)

Sets the connection then creates a new database.

Note

The sqlite driver to doesn't need a connection because it uses the `Illuminate\Support\Storage` helper under the hood.

```
$databaseManager = (new Envor\DatabaseManager)
    ->manage('mysql')
    ->setConnection('any-mysql-connection')
    ->createDatabase('my_new_database');
```

Soft deletes the database and moves it to `deleted_2023_3_2_7_04_38_my_new_database`

```
echo now()->format('Y_m_d_h_i_s_');
// 2023/3/2/7_04_38_
$databaseManager->deleteDatabase(
    databaseName: 'my_new_database',
    deletedAt: now(), // optional: defaults to now(). Uses Carbon.
);
```

No mtime for mysql, simply compares `$daysOld` against the formated time segment in the deleted name `2023_3_2_7_04_38_`. This is done by using `Carbon::createFromFormat('Y_m_H_h_i_s_')`.

```
$databaseManager->cleanupOldDatabases(
    daysOld: 1, // optional, defaults to one
);
```

Creating Managers
-----------------

[](#creating-managers)

Out of the box this package includes managers for sqlite and mysql. You can create your own managers and add them to the managers array in the database-manager config. Feel free to submit a `PR` for any additional custom managers that use standard laravel drivers, such as postgres.

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

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

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

[](#contributing)

Please see [CONTRIBUTING](.github/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)
- Parts of this package are inspired by the `DatabaseManager` classes in [Tenancy for Laravel](https://github.com/archtechx/tenancy)
- [CONTRIBUTING](.github/CONTRIBUTING.md) was copied verbatim from [Spatie's CONTRIBUTING.md](https://github.com/spatie/.github/blob/main/CONTRIBUTING.md)
- This package was generated using [spatie/package-skeleton-laravel](https://github.com/spatie/package-skeleton-laravel)

License
-------

[](#license)

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

###  Health Score

27

—

LowBetter than 47% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 88.6% 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 ~28 days

Recently: every ~14 days

Total

13

Last Release

883d ago

Major Versions

v1.1.2 → v2.0.02024-02-03

### 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 (62 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (4 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (4 commits)")

---

Tags

laravelmariadbmysqllaravelenvorlaravel-database-manager

###  Code Quality

TestsPest

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/envor-laravel-database-manager/health.svg)

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

###  Alternatives

[illuminate/database

The Illuminate Database package.

2.8k54.9M11.7k](/packages/illuminate-database)[defstudio/telegraph

A laravel facade to interact with Telegram Bots

816333.9k3](/packages/defstudio-telegraph)[psalm/plugin-laravel

Psalm plugin for Laravel

3355.3M346](/packages/psalm-plugin-laravel)[spatie/laravel-health

Monitor the health of a Laravel application

87512.0M167](/packages/spatie-laravel-health)[harris21/laravel-fuse

Circuit breaker for Laravel queue jobs. Protect your workers from cascading failures.

44855.7k](/packages/harris21-laravel-fuse)[clickbar/laravel-magellan

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

440902.9k1](/packages/clickbar-laravel-magellan)

PHPackages © 2026

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