thiagomeloo/tenant 问题修复 & 功能扩展

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

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

thiagomeloo/tenant

Composer 安装命令:

composer require thiagomeloo/tenant

包简介

A package to manage multi-tenant applications in Laravel

README 文档

README

Install

  • Install package

        composer require thiagomeloo/tenant
  • Run migrations for creating tables tenants and domains

        php artisan migrate
  • Create folder migrations tenant in database/migrations/tenant/app

        mkdir -p ./database/migrations/tenant/app
  • Publish

    • Config

          php artisan vendor:publish --tag=tenant-config --force
    • Route File

          php artisan vendor:publish --tag=tenant-routes --force 

Usage

  • Create tenant and domain

    <?php
    
    #create tenant and domain
    $tenant = new Thiagomeloo\Tenant\Models\Tenant();
    $tenant->save();
    $tenant->domains()->create(['domain' => 'test.localhost']);
  • Create migration for tenant

    #database/migrations/tenant/app
    <?php
    
    use Illuminate\Database\Migrations\Migration;
    use Illuminate\Database\Schema\Blueprint;
    use Illuminate\Support\Facades\Schema;
    
    return new class extends Migration
    {
        /**
         * Run the migrations.
         */
        public function up(): void
        {
            Schema::create('products', function (Blueprint $table) {
                $table->id();
                $table->string('name');
                $table->timestamps();
            });
        }
    
        /**
         * Reverse the migrations.
         */
        public function down(): void
        {
            Schema::dropIfExists('products');
        }
    };
  • Create Model for Tenant

        # app/Models/Product.php
        <?php
    
        namespace App\Models;
    
        use Illuminate\Database\Eloquent\Factories\HasFactory;
        use Illuminate\Database\Eloquent\Model;
    
        class Product extends Model
        {
    
            use HasFactory;
    
        }
    
  • Create Route for Tenant

        #routes/tenants/web.php
        
        use Illuminate\Support\Facades\Route;
    
        Route::get('example', function () {
            dd("Ok"); 
        }); #output: ok
    
        Route::get('save-product-example', function(){
            Product::create(['name' => 'Product 1']);
            dd("Ok");
        }); #output: ok

Events

Event Namespace
Create new Tenant Model Thiagomeloo\Tenant\Events\TenantCreating
Create database Tenant Thiagomeloo\Tenant\Events\TenantDatabaseCreated
Setup Tenant Thiagomeloo\Tenant\EventsTenantSetupExecuted

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: GPL-3.0-or-later
  • 更新时间: 2023-10-27