yanhaoli/

office-building

office building 是一个为 Laravel 定制的多租户包

1.0.5 2018-07-20 20:45 UTC

This package is not auto-updated.

Last update: 2024-09-29 05:41:58 UTC


README

Office Building

Travis license PRs Welcome

Office Building 是一个易于使用的 Laravel 扩展包,可以帮助您构建基于数据库每个租户的多租户 SaaS 系统。支持 Laravel 5.3+

安装

使用 Composer 安装 Office Building

composer require yanhaoli/office-building

对于 laravel >= 5.5,这样就足够了,多亏了 包发现

对于 laravel <= 5.5,您需要将 Yanhaoli\OfficeBuilding\Providers\OfficeBuildingServiceProvider 添加到您的 config/app.php 的 providers 数组中

Yanhaoli\OfficeBuilding\Providers\OfficeBuildingServiceProvider::class,

使用方法

  1. 首先配置基础项 您需要使用以下命令发布配置文件

    php artisan vendor:publish --provider="Yanhaoli\OfficeBuilding\Providers\OfficeBuildingServiceProvider"

    现在检查 config/officebuilding.php 并根据您的需求进行修改。

  2. 为您的客户开启一个新的办公室

    <?php
    
    namespace App\Http\Controller;
    use OfficeBuilding;
    use App\Company;
    
    class CompanyController extends Controller
    {
      public function create(Request $request)
      {
        $company_name = $request->input('name');
        $database_name = OfficeBuilding::addOffice($company_name);
        $company = new Company;
        $company->name = $company_name;
        $company->database_name = $database_name;
        $company->save();
        return response('created', 201);
      }
    }
  3. 处理特定办公室的请求。例如,获取该办公室的所有员工

    使用 OfficeBuilding::visit 方法将数据库连接切换到特定办公室,并使用回调方法处理请求,任务完成后连接将恢复到之前的状态。

    <?php
    
    namespace App\Http\Controller;
    use OfficeBuilding;
    use App\OfficeBuilding\Employee;
    
    class OfficeEmployeeController extends Controller
    {
      public function browse(Request $request, $office_id)
      {
        $employees = OfficeBuilding::visit($office_id, function(){
          return Employee::all();
        });
    
        return response($employees, 200);
      }
    }

贡献

欢迎对问题修复或功能改进的贡献。

安全漏洞

如果您发现安全漏洞,请通过 hi@yanhaoli.com 发送邮件给我。

许可证

MIT 许可证 (MIT)。有关更多信息,请参阅 MIT 许可证