elysiumrealms/database-router 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

elysiumrealms/database-router

最新稳定版本:1.0.1

Composer 安装命令:

composer require elysiumrealms/database-router

包简介

A Database Router isolate Read Write Connections

README 文档

README

Description

Database Router is an extension for databases using master-slave architecture. This extension ensures that the default connection uses a read-write capable database host and extends an optional router connection to partially apply read-write isolation strategies based on business logic.

Installation

  1. Install elysiumrealms/database-router.

    composer require elysiumrealms/database-router
  2. Configure config/database.php and config/app.php.

    php artisan db:router:install

Read from DB_READ_HOST

To perform read operations using the read host, you can use the following methods:

$model = Model::router()->first();
$model = Admin::where('id', 1)->router()->first();
$model = Admin::router()->where('id', 1)->first();
DB::table('users')->router()->find(1);

Update with DB_WRITE_HOST

To perform update operations using the write host, you can use the following methods:

$model = Model::router()
    ->update(['name' => 'new-name']);
$model = Admin::where('id', 1)->router()
    ->update(['name' => 'new-name']);
$model = Admin::router()->where('id', 1)
    ->update(['name' => 'new-name']);
DB::table('users')->router()
    ->update(['name' => 'new-name']);

统计信息

  • 总下载量: 852
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 3
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-05-19