PHPackages                             faraztanveer/multi-db - 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. faraztanveer/multi-db

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

faraztanveer/multi-db
=====================

Laravel package offering utility functions for seamless management and operations across multiple databases.

v1.0.0(2y ago)054MITPHPPHP ^7.3|^8.0CI passing

Since Jan 15Pushed 1y ago1 watchersCompare

[ Source](https://github.com/faraztanveer/db-shifter)[ Packagist](https://packagist.org/packages/faraztanveer/multi-db)[ RSS](/packages/faraztanveer-multi-db/feed)WikiDiscussions main Synced 1mo ago

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

Multi-DB Laravel Package Documentation
======================================

[](#multi-db-laravel-package-documentation)

Overview
--------

[](#overview)

The **Multi-DB** package is a Laravel library that offers utility functions for seamless management and operations across multiple databases. It allows developers to easily switch between database connections and run database-specific migrations with simple commands.

---

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

[](#installation)

To install the **Multi-DB** package, add it to your Laravel project using Composer:

```
composer require faraztanveer/multi-db
```

### Requirements:

[](#requirements)

- PHP: `^7.3|^8.0`
- Laravel: `^8.0 || ^9.0 || ^10.0`

Once installed, the package will automatically register its service provider.

---

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

[](#configuration)

By default, no additional configuration is required. However, you can publish the package's configuration file for customization:

```
php artisan vendor:publish --provider="MultiDB\MultiDBServiceProvider"
```

---

Features and Usage
------------------

[](#features-and-usage)

### 1. Switch Between Databases

[](#1-switch-between-databases)

The `DatabaseShifter` class lets you dynamically switch database connections at runtime.

#### Example: Switching to a New Database

[](#example-switching-to-a-new-database)

```
// Access the multidb instance
$db = app('multidb');

// Shift to a new database connection
$db->shift('new_database', 'new_host', 'new_username', 'new_password', 'new_port');
```

### 2. Reset to Default Database

[](#2-reset-to-default-database)

To revert back to the default database defined in your `.env` file:

```
$db->setDefaultDb();
```

### 3. Get the Current Database Name

[](#3-get-the-current-database-name)

You can retrieve the current database name at runtime using:

```
$db->currentDb();
```

---

Migrations for Specific Databases
---------------------------------

[](#migrations-for-specific-databases)

This package provides a custom Artisan command that allows you to run migrations on a specific database connection.

### Command: `multidb:migrate`

[](#command-multidbmigrate)

Run migrations for a specific database using this command:

```
php artisan multidb:migrate --database=your_database --path=path/to/migrations --host=127.0.0.1 --username=root --password=your_password --port=3306
```

**Options:**

- `--database` (required): Specify the name of the database.
- `--path`: Path to the migration files (optional).
- `--host`: Database host (default: `127.0.0.1`).
- `--username`: Database username (default: `root`).
- `--password`: Database password (optional).
- `--port`: Database port (default: `3306`).
- `--force`: Run migrations in production without confirmation.

Once the migrations are complete, the connection will automatically reset to the default database.

---

License
-------

[](#license)

This package is licensed under the MIT License. For more information, refer to the [LICENSE](LICENSE) file in the repository.

---

Contribution
------------

[](#contribution)

Contributions are welcome! Feel free to submit issues, suggestions, or pull requests to improve this package.

**GitHub Repository:** [DB Shifter](https://github.com/faraztanveer/db-shifter)

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance35

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity46

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

846d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/8d40505bce8a4988e48a9fe806cf13290209ea0a779d501ec187b0f95d5e2b00?d=identicon)[faraztanveer](/maintainers/faraztanveer)

---

Top Contributors

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

### Embed Badge

![Health badge](/badges/faraztanveer-multi-db/health.svg)

```
[![Health](https://phpackages.com/badges/faraztanveer-multi-db/health.svg)](https://phpackages.com/packages/faraztanveer-multi-db)
```

###  Alternatives

[illuminate/database

The Illuminate Database package.

2.8k52.4M9.3k](/packages/illuminate-database)[cybercog/laravel-love

Make Laravel Eloquent models reactable with any type of emotions in a minutes!

1.2k302.7k1](/packages/cybercog-laravel-love)[cviebrock/eloquent-taggable

Easy ability to tag your Eloquent models in Laravel.

567694.8k3](/packages/cviebrock-eloquent-taggable)[clickbar/laravel-magellan

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

423715.4k1](/packages/clickbar-laravel-magellan)[genealabs/laravel-pivot-events

This package introduces new eloquent events for sync(), attach(), detach() or updateExistingPivot() methods on BelongsToMany relation.

1404.9M8](/packages/genealabs-laravel-pivot-events)[reedware/laravel-relation-joins

Adds the ability to join on a relationship by name.

2121.2M13](/packages/reedware-laravel-relation-joins)

PHPackages © 2026

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