samedi 9 juin 2018

Laravel Tenanti : Default driver not implemented

I want to implement Orchestral/Tenanti for creating databases for each company registered to my app.

When I added Database Connection Resolver as mentioned in https://github.com/orchestral/tenanti I get the following error

InvalidArgumentException Database connection [tenants] is not available.

After googling, I found the answer by cynobone on stackoverflow https://stackoverflow.com/a/33320724/9604136 where setupMultiDatabase is used instead of connection which gave me another error

InvalidArgumentException Default driver not implemented.

For my app, as I was creating new database for each company, I changed accordingly

tenanti.php

'drivers' => [
    'company' => [
        'model'  => App\Company::class,
        'path'   => database_path('tenanti/company'),
        'shared' => false,
    ],
],

AppServiceProvider.php

public function boot()
{

    Tenanti::setupMultiDatabase('tenants', function (Company $entity, array $config) {
        $config['database'] = "comp_{$entity->getKey()}"; 
        // refer to config under `database.connections.tenants.*`.

        return $config;
    });    
}

database.php

'tenants' => [
        'driver'    => 'mysql',
        'host'      => 'dbhost',     // for user with id=1
        'username'  => 'dbusername', // for user with id=1
        'password'  => 'dbpassword', // for user with id=1
        'charset'   => 'utf8',
        'collation' => 'utf8_unicode_ci',
        'prefix'    => '',
        'strict'    => false,
    ],

I am also in dilemma that where to put

$user = App\User::whereSubdomain($request->route()->parameter('tenant'))->first();
Tenanti::driver('user')->asDefaultDatabase($user, 'comp_{id}');

I am trying to authenticate users from my main database and when authenticated, use database made for that authenticated user particularly.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire