Laravel is accessible, powerful, and provides tools required for large, robust applications.
Make sure to change default
DB_CONNECTION=mysql
toDB_CONNECTION=tenant
Then add the following to .env
file:
TENANCY_HOST=127.0.0.1
TENANCY_PORT=3306
TENANCY_DATABASE=DBNAME
TENANCY_USERNAME=USER
TENANCY_PASSWORD=PASS
LIMIT_UUID_LENGTH_32=true
use Hyn\Tenancy\Models\Website;
use Hyn\Tenancy\Contracts\Repositories\WebsiteRepository;
$website = new Website;
$website->uuid = Str::random(10);
app(WebsiteRepository::class)->create($website);
use Hyn\Tenancy\Models\Hostname;
use Hyn\Tenancy\Contracts\Repositories\HostnameRepository;
$hostname = new Hostname;
$hostname->fqdn = 'site.mydomain.com';
$hostname = app(HostnameRepository::class)->create($hostname);
app(HostnameRepository::class)->attach($hostname, $website);
dd($website->hostnames); // Collection with $hostname