不同的数据库,相同的站点....使用Laravel [英] Different databases, same site....with Laravel

查看:82
本文介绍了不同的数据库,相同的站点....使用Laravel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这可能不是适用于stackoverflow的问题....因为它太具体了.

This might not be an appropriate question for stackoverflow....as it might be too specific.

但是我想知道是否有人知道如何安装一个Laravel来服务一个站点.但是根据URL,我可以访问不同的数据库.

But I was wondering if anybody knows how I would have one installation of Laravel, serving a site. But depending on the url, I can access different databases.

即...

www.mainsite.com/company1/login-数据库1

www.mainsite.com/company1/login - database1

www.mainsite.com/company1/users-数据库1

www.mainsite.com/company1/users - database1

..

www.mainsite.com/company2/login-database2

www.mainsite.com/company2/login - database2

www.mainsite.com/company2/users-数据库2

www.mainsite.com/company2/users - database2

因此,在上述情况下,所服务的站点是完全相同的站点. 但是,当然,每个部分都有一个登录名,并访问不同的数据库.

So in the cases above, the site being served is the exact same site. But of course, each part has a login, and accesses a different database.

我知道我可以通过安装多个laravel来做到这一点,而那实际上是我现在如何做到的....

I know I can do this by having multiple installations of laravel, and thats actually how Im doing it right now....

但是我只想更新一个版本....而不必将所做的更改复制到所有不同的文件夹中.

But I wanna be able to just update ONE version....instead of having to copy my changes to all the different folders.

然后将一个站点提供给所有多个不同的公司. 他们只能访问他们的数据库

Then just serve that one site to all the multiple different companies. With them having access to only their database

这可能吗?

推荐答案

我用于此目的的一种技术是为新客户生成数据库名称,这些新客户注册并将其存储在我的主数据库中.该数据库也将在此时创建和迁移.在此之后每次用户登录时,软件都会使用以下命令查找其数据库名称并为他们动态设置配置:

One technique I used for this was to generate database names for new customers who sign up and store that in my master database. The database would be created and migrated at this time as well. When the user logins in everytime after that, the software looks up his database name and sets the config for them on the fly using:

Config::set(['database.connections.customerid']).

您仍然可以拥有Laravel和Eloquent的所有优惠,而不必依赖原始查询.这也使您无需管理大型配置文件.我还创建了与目录名称匹配的资源目录,以便它们可以在运行与其他所有人完全相同的堆栈的同时拥有一个带有视图文件和样式的自定义前端站点.

You can still have all the goodies Laravel and Eloquent offer and not be reliant on raw queries. This also frees you from managing a large config file. I also created resource directories matching their schema name so they could have a custom front facing site with view files and styles while running the exact same stack as everyone else.

这篇关于不同的数据库,相同的站点....使用Laravel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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