DanTheDJ / multitenant

The minimalist Laravel MultiTenant package enables easy multi-tenant applications by dynamically setting the database connection + name and adding a globally available --tenant option to Artisan. Enjoy!
MIT License
14 stars 4 forks source link

When installing tenants database, 'tenants' table cannot be found. #1

Closed DanTheDJ closed 7 years ago

DanTheDJ commented 7 years ago

When the command php artisan migrate --path /vendor/danthedj/multitenant/migrations is run, an error is displayed:

SQLSTATE[42S02]: Base table or view not found: 1146 Table 'master_tenants.tenants' doesn't exist (SQL: select * from `tenants` where `subdomain` is null or `alias_domain` is null or `id` is null limit 1)

This error occurs due to the TenantResolver trying to resolve a domain of null.

DanTheDJ commented 7 years ago

By checking the value of domain in the function resolveRequest() you can either assign tenant to null or to the value from the database:

$domain = (new ArgvInput())->getParameterOption('--tenant', null);

try
{
    $model = $this->tenant;

    (is_null($domain) ? $tenant = null : $tenant = $model->where('subdomain', '=', $domain)->orWhere('alias_domain', '=', $domain)->orWhere('id', '=', $domain)->first());

}
catch (\Exception $e)
{
    $tenant = null;
    echo $e->getMessage();
}