Laravel7管弦乐队/tenanti,多个数据库不工作
有人能帮忙吗 租户版本:^5.0 Laravel版本:7.x PHP版本:7.4 数据库驱动程序&版本:mysql-5.7.31 说明: 当我安装tenanti版本时,服务提供程序中出现错误Laravel7管弦乐队/tenanti,多个数据库不工作,laravel,multi-tenant,orchestra,Laravel,Multi Tenant,Orchestra,有人能帮忙吗 租户版本:^5.0 Laravel版本:7.x PHP版本:7.4 数据库驱动程序&版本:mysql-5.7.31 说明: 当我安装tenanti版本时,服务提供程序中出现错误 Illuminate\Contracts\Container\BindingResolutionException Unable to resolve dependency [Parameter #1 [ array $config ]] in class App\Providers\AppServiceP
Illuminate\Contracts\Container\BindingResolutionException
Unable to resolve dependency [Parameter #1 [ array $config ]] in class App\Providers\AppServiceProvider
复制步骤:
“管弦乐队/租户”:“^5.0”
在appServiceProvider页面中添加,如下所示。我已经删除了我的代码,并显示了我在哪里添加了租户代码。请原谅
use Orchestra\Support\Facades\Tenanti;
public function boot()
{
Tenanti::connection('tenants', function (Subdomain $entity, array $config) {
//var_dump($entity);die;
$config['database'] = "sc_{$entity->domain_name}";
return $config;
});
}
在App/Config/chestration/tenanti.php中
<?php
return [
/*
|----------------------------------------------------------------------
| Queue Configuration
|----------------------------------------------------------------------
|
| Set queue connection name to be use for running all the queues.
|
*/
'queue' => env('TENANTI_QUEUE_CONNECTION', 'default'),
/*
|----------------------------------------------------------------------
| Driver Configuration
|----------------------------------------------------------------------
|
| Setup your driver configuration to let us match the driver name to
| a Model and path to migration.
|
*/
'drivers' => [
'user' => [
'model' => App\Models\Subdomain::class,
'paths' => [
database_path('tenant/users'),
],
'shared' => true,
],
],
];
在database.php中
'tenants' => [
'driver' => 'mysql',
'host' => env('DB_HOST', ''),
'port' => env('DB_PORT', '3306'),
'database' => '',
'username' => env('DB_USERNAME', ''),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'strict' => false,
'contype'=>'tenant',
],
在中间件中,我打过如下电话
use DB;
use App\Models\Subdomain;
use Orchestra\Support\Facades\Tenanti;
//$subDomainDetails Object
**object(App\Models\Subdomain)[1308]
protected 'connection' => string 'mysql' (length=5)
protected 'table' => string 'subdomains' (length=10)
protected 'primaryKey' => string 'id' (length=2)
protected 'keyType' => string 'int' (length=3)
public 'incrementing' => boolean true
protected 'with' =>
array (size=0)
empty
protected 'withCount' =>
array (size=0)
empty
protected 'perPage' => int 15
public 'exists' => boolean true
public 'wasRecentlyCreated' => boolean false
protected 'attributes' =>
............
);**
$subDomainDets = Subdomain::where('domain_name', $subdomain)->first();
Tenanti::driver('user')->asDefaultConnection($subDomainDets, config('DB_PREFIX').$subdomainname);
当我使用Laravel 5.4时,同样的代码工作得非常好。“管弦乐队/租户”:“^3.0”
现在我已经将我的php版本升级到7.4,并升级了“laravel/framework”:“^7.0”版本和orchestra/tenanti:^5.0
已成功安装Composer
在我运行子域之后,它没有连接到租户数据库。获取错误,如下所示
Illumb\Contracts\Container\BindingResolutionException
无法解析类App\Providers\AppServiceProvider中的依赖项[Parameter#1[array$config]]
在vendor/chestration/tenanti/src/Migrator/Operation.php中,我检查了代码
直到这行代码正确执行,但在这之后会出现错误
if (! \is_null($tenants) && \is_null($repository->get($name))) {
echo "executing this line";
$config = $this->app->call($tenants['resolver'], [
'entity' => $entity,
'template' => $tenants['template'],
'connection' => $connection,
'migrator' => $this,
]);
echo "not executing this line. may be issue with above code.";
var_dump($config);
$repository->set($name, $config);
}
有人能帮我吗
if (! \is_null($tenants) && \is_null($repository->get($name))) {
echo "executing this line";
$config = $this->app->call($tenants['resolver'], [
'entity' => $entity,
'template' => $tenants['template'],
'connection' => $connection,
'migrator' => $this,
]);
echo "not executing this line. may be issue with above code.";
var_dump($config);
$repository->set($name, $config);
}