Php 如何在Laravel 5.2中使用HipsterJazzbo/London包-单数据库多租户?
我正在为Laravel 5.2+使用单数据库多租户解决方案。我有一个companys表,所有其他表都有一个company\u id列 我不知道如何在全局中间件、身份验证系统或基本控制器的构造函数中实现调用lown::addTenant($tenantColumn,$tenantId)。。。我很困惑 我该怎么做 参数$tenantColumn是否等同于每个表的company\u id列 参数$tenantId是否引用列company\u id中包含的每个公司的idPhp 如何在Laravel 5.2中使用HipsterJazzbo/London包-单数据库多租户?,php,mysql,laravel,laravel-5.2,laravel-5.1,Php,Mysql,Laravel,Laravel 5.2,Laravel 5.1,我正在为Laravel 5.2+使用单数据库多租户解决方案。我有一个companys表,所有其他表都有一个company\u id列 我不知道如何在全局中间件、身份验证系统或基本控制器的构造函数中实现调用lown::addTenant($tenantColumn,$tenantId)。。。我很困惑 我该怎么做 参数$tenantColumn是否等同于每个表的company\u id列 参数$tenantId是否引用列company\u id中包含的每个公司的id 谢谢大家! 全局中间件不是一个好
谢谢大家! 全局中间件不是一个好地方,因为您无法访问经过身份验证的用户。解决方案是创建路由中间件,例如:
<?php
namespace App\Http\Middleware;
use Closure;
use HipsterJazzbo\Landlord\Facades\Landlord;
use Illuminate\Support\Facades\Auth;
class LimitToCurrentCompany
{
public function handle($request, Closure $next)
{
if (Auth::check()) {
$tenant = Auth::user()->currentCompany;
Landlord::addTenant($tenant);
}
return $next($request);
}
}
然后在路由文件中:
Route::group(['middleware' => 'limitToCurrentCompany'], function () {
// your routes
});
是的,正如评论中所说,$tenantColumn是公司id,$tenantId是公司id。全局中间件不是一个好地方,因为您无法访问经过身份验证的用户。解决方案是创建路由中间件,例如:
<?php
namespace App\Http\Middleware;
use Closure;
use HipsterJazzbo\Landlord\Facades\Landlord;
use Illuminate\Support\Facades\Auth;
class LimitToCurrentCompany
{
public function handle($request, Closure $next)
{
if (Auth::check()) {
$tenant = Auth::user()->currentCompany;
Landlord::addTenant($tenant);
}
return $next($request);
}
}
然后在路由文件中:
Route::group(['middleware' => 'limitToCurrentCompany'], function () {
// your routes
});
是的,正如评论中所说,$tenantColumn是公司id,$tenantId是公司id。快速查看文档,
$tenantColumn
将是公司id
,$tenantId
将是特定公司的id。这种方法不起作用吗?快速查看文档,$tenantColumn
将是公司id
,$tenantId
将是特定公司的id。这种方法是否有问题?