PHPackages                             rolice/laravel-db-switch - 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. rolice/laravel-db-switch

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

rolice/laravel-db-switch
========================

Simple and light DB switcher for Laravel.

1.0(9y ago)31.9k1MITPHPPHP &gt;=5.6

Since Mar 16Pushed 8y ago1 watchersCompare

[ Source](https://github.com/Rolice/laravel-db-switch)[ Packagist](https://packagist.org/packages/rolice/laravel-db-switch)[ RSS](/packages/rolice-laravel-db-switch/feed)WikiDiscussions master Synced 2mo ago

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

Database Switch for Laravel and Lumen
=====================================

[](#database-switch-for-laravel-and-lumen)

Composer package for Laravel that enables easy replacement of database instance. The package is highly suitable for similar databases that run different copies of a same program.

This package is being developed and tested under **Laravel 5.3**, **Laravel 5.4** and **Lumen 5.4**. However it should be compatible with the older releases of Laravel, expecting at least as versions 5.0.

Prerequisites
-------------

[](#prerequisites)

### Composer

[](#composer)

You will need composer to setup your project. You can skip this point most-likely, since it is a must for your Laravel or Lumen project, but if for some reason you are new to it you will find the official [composer website](http://getcomposer.org/) very useful. You will find detailed documentation, use-cases and scenarios plus full instruction set about the downloading and installing composer, including all the download files needed.

### Laravel/Lumen Project

[](#laravellumen-project)

We assume you have prepared and installed already your Laravel or Lumen project and you have navigated to its folder with your console/terminal application.

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

[](#installation)

The package is installed in the traditional way through composer. You can do this by executing the following command in the folder of your Laravel project:

```
composer require 'rolice/laravel-db-switch' # with globally installed composer
```

or if you have no global composer installation exists with your project, but simply `composer.phar` file:

```
php /path/to/composer.phar require 'rolice/laravel-db-switch' # with local composer.phar file
```

The above should add the package with your project directly.

Alternatively, you can manually add `rolice/laravel-db-switch` in your `composer.json` file in the `require` section and then you will be able to install it with:

```
composer install
```

or again if no global composer installation exists:

```
php /path/to/composer.phar install
```

**Note**: That you will have to replace */path/to/composer.phar* in the examples above with the actual path where you have downloaded a copy of the official *composer.phar*. More information could be found on the previous section with the [Prerequisites](##Prerequisites).

After you are ready with the package installation we have to enable the service provider inside the application config.

**For Laravel**: Just open the `{your/project/folder}/config/app.php` file of your application (by default should be located there).

Add the service provider inside the `providers` section (array):

```
Rolice\LaravelDbSwitch\DbSwitchServiceProvider::class,
```

Preferably under the comment like:

```
/*
 * Package Service Providers...
 */
 Rolice\LaravelDbSwitch\DbSwitchServiceProvider::class,
```

**For Lumen**: You should register the service provider inside `bootstrap/app.php` like:

```
/*
|--------------------------------------------------------------------------
| Register Service Providers
|--------------------------------------------------------------------------
|
| Here we will register all of the application's servipoce providers which
| are used to bind services into the container. Service providers are
| totally optional, so you are not required to uncomment this line.
|
*/
// ...
$app->register(Rolice\LaravelDbSwitch\DbSwitchServiceProvider::class);
// ...
```

**For Laravel**: Now you can register the facade in the section below named `aliases` (array), in the same file `config/app.php` by adding the following like there:

```
'DbSwitch' => Rolice\LaravelDbSwitch\Facades\DbSwitch::class,
```

**For Lumen**: You can enable facades and pass it along with:

```
$app->withFacades(true, [
    Rolice\LaravelDbSwitch\Facades\DbSwitch::class => 'DBSwitch'
]);
```

...or you can directly enable it the same way, but with raw code, an example:

```
/*
|--------------------------------------------------------------------------
| Register Facades
|--------------------------------------------------------------------------
|
| A config section for registering facades through class aliases.
|
*/

class_alias(\Rolice\LaravelDbSwitch\Facades\DbSwitch::class, 'DbSwitch');
```

Now the package should be available and running with your project.

Usage
-----

[](#usage)

You can use the package service either through the facade `DbSwitch` or through the singleton instance inside the IoC service container of Laravel:

```
// Usage through the facade - DbSwitch
DbSwitch::to('my-cool-db'); // The defaut connection
DbSwitch::connectionTo('my-cool-conenction', 'my-cool-db'); // A specific connection database

// Usage through the Laravel Service Container (IoC)
app('db.switch')->to('my-cool-db'); // The defaut connection
app('db.switch')->connectionTo('my-cool-conenction', 'my-cool-db'); // A specific connection database
```

That is the whole scope of this package.

**Enjoy** switching your databases! :P

###  Health Score

30

—

LowBetter than 65% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity20

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity58

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

3342d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/749cf1dfa9fd70be7bbcb900213e22ded804858f6e92baadabc6456536eb18ce?d=identicon)[rolice](/maintainers/rolice)

---

Top Contributors

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

---

Tags

phplaraveldatabasedbruntimeswitch

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/rolice-laravel-db-switch/health.svg)

```
[![Health](https://phpackages.com/badges/rolice-laravel-db-switch/health.svg)](https://phpackages.com/packages/rolice-laravel-db-switch)
```

###  Alternatives

[spiritix/lada-cache

A Redis based, automated and scalable database caching layer for Laravel

591444.8k2](/packages/spiritix-lada-cache)[glushkovds/phpclickhouse-laravel

Adapter of the most popular library https://github.com/smi2/phpClickHouse to Laravel

2031.2M2](/packages/glushkovds-phpclickhouse-laravel)[cybercog/laravel-clickhouse

ClickHouse migrations for Laravel

163166.8k](/packages/cybercog-laravel-clickhouse)[webparking/laravel-db-rebuild

A laravel package that allows for quick database rebuilds with presets.

448.8k](/packages/webparking-laravel-db-rebuild)[illuminatech/config

Provides support for Laravel application runtime configuration managed in persistent storage

14921.0k1](/packages/illuminatech-config)[sebastiaanluca/laravel-boolean-dates

Automatically convert Eloquent model boolean attributes to dates (and back).

40111.7k1](/packages/sebastiaanluca-laravel-boolean-dates)

PHPackages © 2026

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