承接 ronu/multitenancy-laravel 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

ronu/multitenancy-laravel

Composer 安装命令:

composer require ronu/multitenancy-laravel

包简介

AppContext-integrated multi-tenancy for Laravel.

README 文档

README

A lightweight multi-tenancy layer designed to integrate with ronu/laravel-app-context. It provides global tenant scoping, tenant-aware model behavior, and middleware validation, with minimal overhead when disabled.

Key Features

  • Global tenant scope for Eloquent models
  • Tenant-aware model creation and updates
  • Per-channel enable/disable based on AppContext channels
  • Auto-detection of tenancy based on channel configuration
  • Strict, soft, or disabled enforcement modes
  • Optional bypass mode for superusers
  • Artisan command to inspect status

Requirements

  • PHP 8.1+
  • Laravel 9, 10, or 11
  • ronu/laravel-app-context

Installation

  1. Require the AppContext package.
  2. Require this package (or include it as a local package).
  3. Register the service provider if you are not using auto-discovery.
  4. Publish the config file.
php artisan vendor:publish --tag=tenancy-config

Configuration

Main config file: config/tenancy.php

Environment variables (from .env.example):

  • TENANCY_ENABLED true | false | empty (auto-detect)
  • TENANCY_COLUMN default tenant column, e.g. tenant_id
  • TENANCY_ENFORCEMENT_MODE strict | soft | disabled
  • TENANCY_ADMIN_ENABLED override per channel
  • TENANCY_MOBILE_ENABLED override per channel
  • TENANCY_SITE_ENABLED override per channel
  • TENANCY_PARTNER_ENABLED override per channel
  • TENANCY_LOG_BYPASSES true | false
  • TENANCY_LOG_CONTEXT_CHANGES true | false
  • TENANCY_ALERT_VIOLATIONS true | false

AppContext Integration

This package reads the current channel and tenant from AppContext:

  • app-context.channels.{channel}.tenant_mode determines default behavior.
  • TenantOwnershipValidator hydrates the tenant context from AppContext.
  • TenantScope applies tenant filtering automatically.

Usage

Apply tenant behavior to a model

use Ronu\MultitenancyLaravel\Traits\TenantAware;

class Order extends Model
{
    use TenantAware;
}

Tenant scope helpers

Order::query()->withoutTenantScope()->get();
Order::query()->forTenant($tenantId)->get();

Middleware

Register TenantOwnershipValidator after ctx.auth / ctx.bind so it can read AppContext.

Status command

php artisan tenancy:status
php artisan tenancy:status --detailed

Security Notes

  • Cross-tenant operations require a superuser resolver.
  • Tenant ID modification on updates is blocked by TenantAware.

Known Issues (Resolved)

  • Namespace mismatches were standardized to Ronu\\MultitenancyLaravel.

License

MIT

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-02-10

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固