Can anyone please help on this.
Tenanti Version: ^5.0
Laravel Version: 7.x
PHP Version: 7.4
Database Driver & Version: mysql-5.7.31
Description:
When I install tenanti version getting an error in service provider.
Illuminate\Contracts\Container\BindingResolutionException
Unable to resolve dependency [Parameter #1 [ array $config ]] in class App\Providers\AppServiceProvider
Steps To Reproduce:
"orchestra/tenanti": "^5.0",
In appServiceProvider page added like below. I have removed my code and showing Where i have added Tenant code. Please excuse.
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;
});
}
In App/Config/Orchestra/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,
],
],
];
In database\tenant\users added migration files.
in App/Http/Observer added UserObserver
namespace App\Observers;
use Orchestra\Tenanti\Observer;
class UserObserver extends Observer
{
public function getDriverName()
{
return 'user';
}
}
In 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',
],
In Middleware I have called like below
//$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' =>
............
);
use DB;
use App\Models\Subdomain;
use Orchestra\Support\Facades\Tenanti;
$subDomainDets = Subdomain::where('domain_name', $subdomain)->first();
Tenanti::driver('user')->asDefaultConnection($subDomainDets, config('DB_PREFIX').$subdomainname);
Same code worked Perfectly when I have Laravel 5.4. "orchestra/tenanti": "^3.0",
Now I have upgraded my php version to 7.4 and upgraded "laravel/framework": "^7.0" version and orchestra/tenanti: ^5.0
Composer installed successfully.
After i run Subdomain Its not connecting to tenant db. Getting error like below.
Illuminate\Contracts\Container\BindingResolutionException
Unable to resolve dependency [Parameter #1 [ <required> array $config ]] in class App\Providers\AppServiceProvider
In vendor/orchestra/tenenti/src/Migrator/Operation.php I have checked the code.
Until this line code is executing correctly but after that getting that error.
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);
}