public function generateConfigurationArray(Website $website): array
{
switch ($mode) {
case static::DIVISION_MODE_SEPARATE_DATABASE:
// ORIGINAL CODE
$clone['username'] = $clone['database'] = $website->uuid;
$clone['password'] = $this->passwordGenerator->generate($website);
break;
case static::DIVISION_MODE_BYPASS:
break;
default:
throw new ConnectionException("Division mode '$mode' unknown.");
}
}
i would like to override this function from Hyn\Tenancy\Database\Connection (laravel multi-tenant) but i have no idea at all, anyone give me some example?
public function generateConfigurationArray(Website $website): array
{
switch ($mode) {
case static::DIVISION_MODE_SEPARATE_DATABASE:
// MAKE CHANGE CODE
$clone['username'] = 'username';
$clone['database'] = $website->uuid;
$clone['password'] = 'password';
break;
case static::DIVISION_MODE_BYPASS:
break;
default:
throw new ConnectionException("Division mode '$mode' unknown.");
}
}
i had try service provider, but becuase the function have a parameter, i dont know how to pass it , and got error too this is the provider code i put into register $this->app->bind('Hyn\Tenancy\Database\Connection', 'App\Vendor\CustomConnection');
PHP Fatal error: Declaration of App\Vendor\CustomConnection::get() must be compatible with Hyn\Tenancy\Database\Connection::get(): Illuminate\Database\Connection in this is the error i got
CustomConnectionServiceProvider.php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use Hyn\Tenancy\Providers\Tenants\ConnectionProvider as ConnectionProvider;
use Hyn\Tenancy\Database\Connection;
class CustomConnectionServiceProvider extends ConnectionProvider
{
/**
* Register services.
*
* @return void
*/
public function register()
{
/*$loader = \Illuminate\Foundation\AliasLoader::getInstance();
$loader->alias('Hyn\Tenancy\Database\Connection', 'app\Vendor\CustomConnection');*/
$this->app->bind('Hyn\Tenancy\Database\Connection', 'App\Vendor\CustomConnection');
}
/**
* Bootstrap services.
*
* @return void
*/
public function boot()
{
}
}
app/vendor/CustomConnection.php
<?php
namespace App\Vendor;
use Hyn\Tenancy\Database\Connection as Connection;
class CustomConnection extends Connection
{
public function generateConfigurationArray(Website $website): array
{
$clone = config(sprintf(
'database.connections.%s',
$website->managed_by_database_connection ?? $this->systemName()
));
$mode = config('tenancy.db.tenant-division-mode');
$this->emitEvent(new Events\Database\ConfigurationLoading($mode, $clone, $this));
// Even though username/password mutate, let's store website UUID so we can match it up.
$clone['uuid'] = $website->uuid;
switch ($mode) {
case static::DIVISION_MODE_SEPARATE_DATABASE:
$clone['username'] = 'username'
%clone['database'] = $website->uuid;
$clone['password'] = 'password';
break;
case static::DIVISION_MODE_SEPARATE_PREFIX:
$clone['prefix'] = sprintf('%d_', $website->id);
break;
case static::DIVISION_MODE_BYPASS:
break;
default:
throw new ConnectionException("Division mode '$mode' unknown.");
}
$this->emitEvent(new Events\Database\ConfigurationLoaded($clone, $this));
return $clone;
}
}