PHPackages                             luminee/switcher - 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. [CLI &amp; Console](/categories/cli)
4. /
5. luminee/switcher

ActiveLibrary[CLI &amp; Console](/categories/cli)

luminee/switcher
================

0.9.0.1(12mo ago)0121MITPHPPHP &gt;=8.0

Since May 13Pushed 12mo ago1 watchersCompare

[ Source](https://github.com/Luminee/switcher)[ Packagist](https://packagist.org/packages/luminee/switcher)[ RSS](/packages/luminee-switcher/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (2)Dependencies (1)Versions (5)Used By (1)

Luminee Switcher
================

[](#luminee-switcher)

Laravel数据库连接切换扩展包，支持动态切换默认数据库连接和添加额外连接配置。

功能特性
----

[](#功能特性)

- 动态切换默认数据库连接
- 支持添加额外数据库连接配置
- 自动恢复原始连接
- 支持多层级连接配置

安装
--

[](#安装)

通过Composer安装：

```
composer require luminee/switcher
```

配置
--

[](#配置)

1. 发布配置文件：

```
php artisan vendor:publish --provider="Luminee\Switcher\SwitcherServiceProvider"
```

2. 在`config/switcher.php`中添加额外连接配置：

```
return [
    'extra_connections' => [
        // 简单连接配置
        'mysql2' => [
            'driver' => 'mysql',
            'host' => '127.0.0.1',
            // 其他配置...
        ],

        // 多层级连接配置
        'project' => [
            'dev' => [
                'driver' => 'mysql',
                // 配置...
            ],
            'prod' => [
                'driver' => 'mysql',
                // 配置...
            ]
        ]
    ]
];
```

使用方法
----

[](#使用方法)

### 基本用法

[](#基本用法)

```
use Luminee\Switcher\Facades\Switcher;

Switcher::run(function() {
    // 这里使用新连接执行操作
    return User::all();
}, 'mysql2');
```

### 使用多层级连接

[](#使用多层级连接)

```
Switcher::run(function() {
    // 使用project_dev连接
    return User::all();
}, 'project_dev');
```

注意事项
----

[](#注意事项)

1. 连接切换仅在闭包函数内有效
2. 操作完成后会自动恢复原始连接
3. 连接名称会自动转换为小写
4. 多层级连接会自动添加前缀（如`project_dev`）

开源协议
----

[](#开源协议)

MIT

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance50

Moderate activity, may be stable

Popularity5

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity35

Early-stage or recently created project

 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

Every ~8 days

Total

2

Last Release

363d ago

PHP version history (2 changes)0.5.5.1PHP &gt;=7.0

0.9.0.1PHP &gt;=8.0

### Community

Maintainers

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

---

Top Contributors

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

### Embed Badge

![Health badge](/badges/luminee-switcher/health.svg)

```
[![Health](https://phpackages.com/badges/luminee-switcher/health.svg)](https://phpackages.com/packages/luminee-switcher)
```

###  Alternatives

[acdphp/laravel-schedule-police

Stop, start or execute scheduled commands from a simple dashboard without redeploying, while maintaining the visibility, control, and reviewability of the configurations in your codebase.

5116.9k](/packages/acdphp-laravel-schedule-police)[jakyeru/laravel-shell

Laravel-Shell adds a terminal interface to your web application, allowing you to run shell commands directly from your browser.

166.1k](/packages/jakyeru-laravel-shell)

PHPackages © 2026

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