Laravel多租户方法.从哪儿开始 [英] Laravel multi-tenant approach. Where to start

查看:247
本文介绍了Laravel多租户方法.从哪儿开始的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个完整的应用程序编码.现在,唯一缺少的就是使它成为多租户.

I've a full application coded. Now, the only part missing is to make it multi-tenancy.

我希望允许客户注册到我的应用程序网站中,并获得仅具有该帐户完全空数据库的应用程序实例.

I want to allow clients to register into my application website and get an instance of the application with a completely empty database only for that account.

我曾经考虑过要在环境中玩耍,但是我不确定这是否是一种好方法:

I've thought to play with environments, but I'm not sure if this is a good approach:

config
    - user1
        - database.php
    - user2
        - database.php
    - ...

我还考虑了一个唯一的配置文件,其中包含有关每个帐户的数据库信息,并根据子域名设置数据库连接.就像我在这篇文章中看到的一样:

I've also thought about a unique config file containing the database information about every account and set the database connection based on the subdomain name. Something like I've seen in this post:

Laravel4中的多租户

还有其他想法或更好的方法来完成这一部分吗?

Any other idea or better approach to do this part?

推荐答案

您的解决方案需要1000个文件夹才能容纳1000个用户. 1000个数据库,如果在应用程序生命周期中发生任何更改,则进行数千次迁移. 你不要这个,相信我.

Your solutions require 1000 folders for 1000 users. 1000 databases, thousand migrations if anything changes during application live cycle. You don't want this, trust me.

简而言之,请创建一个数据库并使用标志/外键将数据关联给用户.

Instead, create one database and use flags/foreign keys to assing data to users, simply said.

这篇关于Laravel多租户方法.从哪儿开始的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆