muralibobby2015 17 Posting Pro

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);
}

Dani AI

Generated

Quick diagnosis and why the container error points at AppServiceProvider

The exception is coming from Laravel's container trying to call the resolver callback that was registered inside the service provider. Laravel matches the arguments it will pass by parameter name and by type. If the package invokes the callable with a specific named argument (the template array) but the callback declares a differently named, required array parameter, the container cannot auto-resolve that array and throws the BindingResolutionException. The provider shows up in the error because the closure is defined there.

What to change (practical fixes)

  • Make the resolver accept the package-provided parameter name so the container can match it (for example, name the second parameter to match the package's template argument and keep the array type-hint).
  • Alternatively, make that array parameter optional (give it a default value) or register an invokable class with a method signature that matches the package call; using an invokable class avoids closure-binding quirks inside a provider.
  • After changes run the usual clears: php artisan config:clear, php artisan cache:clear and composer dump-autoload to remove cached signatures.

Quick troubleshooting checklist

  • Confirm the resolver callback signature matches what the package actually passes (inspect the package call site to see the argument names).
  • Ensure the model type-hint used in the resolver is the correct, importable class (wrong namespace/type-hint can also confuse injection).
  • Log the parameters received by the resolver (temporary debug) to confirm what is being passed and to verify the template array contents.

Note: the error is not a DB connection failure — it is a parameter-matching issue between the Tenanti callback and Laravel's container. Adjusting the callback signature to match what the package supplies will resolve the BindingResolutionException.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.