找到你要的答案

Q:orchestral/tenanti Driver not supported error?

Q:管弦乐/ tenanti驱动程序不支持的错误吗?

I am trying to use the orchestral/tenanti package in my laravel 5 installation to get a multi database multi tenant architecture up and running but I am not sure how to proceed after the installation.

I have followed the installation instructions carefully and installed the package through composer, defined the service providers and the alias in the config/app.php file and I also went ahead ahead and edited the AppServiceProvider's boot method.

Now this section in the documentation is blurry to me. What is it supposed to mean?

And after that, how am I supposed to proceed from here on? When I try the new artisan commands that come with the package like tenanti:install and others like it I keep getting an error Driver [mysql] not supported and so on. What am I doing wrong and how to set up this package correctly and where to go after the package has been set up.

Where do I create the migration files for the main DB and where do I create the migration files for the tenant DB? And how do I use this package inside my code?

我想我得多laravel 5安装数据库的多租户架构和运行使用管弦乐/ tenanti包,但我不知道如何安装后进行。

我按照安装说明安装包通过仔细和作曲家,定义了服务提供商和配置/ app.php文件别名,我也继续前进并编辑appserviceprovider的引导方法。

现在文档中的这一部分对我来说很模糊。这是什么意思?

And after that, how am I supposed to proceed from here on? When I try the new artisan commands that come with the package like tenanti:install and others like it I keep getting an error Driver [mysql] not supported and so on. What am I doing wrong and how to set up this package correctly and where to go after the package has been set up.

我在哪里创建主数据库的迁移文件,在哪里创建租户DB的迁移文件?我如何在我的代码中使用这个包?

answer1: 回答1:

The driver here describe the unique identifier for your tenant, tenant could be based on company, team, site etc. You might even have multiple drivers in a single application.

So in order to describe a driver, you must decide how you want to structure your application, let say you decide that user can have multiple sites, and each site has it's own tenant database.

'drivers' => [
    'site' => [
        'model' => App\Site::class, \\ The eloquent model for `sites` table.
        'migration' => 'tenant_migrations',
        'path' => database_path('tenanti/site'),
    ]
],

Now assume that you have created the App\Site model, and create the observer as describe in the readme.

You can create new migration schema by using php artisan tenanti:make site create_posts_table. This command would now create a new migration schema in database/tenant/site/.

Once you have the migration, create a record through Eloquent, or manually and run php artisan tenanti:migrate site.

Problem with Multi-Database Tenant

It easy to make your database connection to swap between the default and current tenant (using migration etc), however when we want to run the migration from a command line, it not possible to dynamically swap between connection as we don't know this information (console doesn't use middleware).

To solve this, you need to setup Database Connection Resolver

这里的驱动程序描述了您的租户的唯一标识符,租户可以基于公司,团队,站点等,您甚至可能有多个驱动程序在一个单一的应用程序。

因此,为了描述一个驱动程序,你必须决定如何构建你的应用程序,让你说你决定用户可以有多个站点,每个站点都有自己的租户数据库。

'drivers' => [
    'site' => [
        'model' => App\Site::class, \\ The eloquent model for `sites` table.
        'migration' => 'tenant_migrations',
        'path' => database_path('tenanti/site'),
    ]
],

现在假设你创建的应用程序、网站模式,并创建观察描述的自述。

您可以使用PHP的工匠tenanti创建新的迁移模式:让网站create_posts_table。此命令将在数据库/租户/站点创建新的迁移模式。

一旦你有了迁移,创造纪录的雄辩,或手动运行PHP的工匠tenanti:迁移网站。

Problem with Multi-Database Tenant

它很容易使您的数据库连接之间的默认和当前租户(使用迁移等)交换,但是当我们要运行从命令行的迁移,它不可能动态连接之间的连接,因为我们不知道这个信息(控制台不使用中间件)。

为了解决这个问题,你需要设置数据库连接旋转变压器

php  laravel  laravel-5  multi-tenant