I've been following the guide here and have it all setup. The guide explains how to grab the subdomain and use this to connect to the correct database. Each tenant will have its own db and there will also be a master _admin db. This _admin db will have a tenants table with a subdomain column. There is a filter that is run each time that checks the subdomain against the tenants table. The problem comes as the database config file isnt set to the master _admin db which includes the tenants table but to mysql_tenant, where tenant is set on the fly.
I think I can get around this by manually specifying the db for the filter to connect to, here is the code I have for the filter.
Route::filter('verifyTenant', function($route, $request)
{
$host = $request->getHost();
$parts = explode('.', $host);
$subdomain = $parts[0];
# Ping DB for tenant match. Note that my Tenant model directs laravel to ping the tenant table in the master db to verify tenant
$tenant = Tenant::where('subdomain', '=', $subdomain)->first();
# If tenant database exists but tenant not in master db, redirect to homepage
if ($tenant == null) return Redirect::to('http://www.'.Config::get('app.domain'));
});
The line i need to alter is:
$tenant = Tenant::where('subdomain', '=', $subdomain)->first();
I've tried doing the following but get an error:
$tenant = DB::connection('mysql')->Tenant::where('subdomain', '=', $subdomain)->first();
The error i get is:
Symfony \ Component \ Debug \ Exception \ FatalErrorException
syntax error, unexpected '::' (T_PAAMAYIM_NEKUDOTAYIM)