Magno Alberto
Magno Alberto

Reputation: 668

hyn multi-tenant v5.2 - how to create the website, hostname and associate

I created a class 'CreateTenant' in 'App\Console\Commands' and I can even create the website:

    $website = new Website();
    app(WebsiteRepository::class)->create($website);

But I am not able to create a hostname and perform the association between them. I would like to create subdomains, something like sub1.domain.local, sub2.domain.local, etc

I imagine I should use something like this...

    $hostname = new Hostname();

    app(HostnameRepository::class)->attach($hostname, $website);

    $hostname->website()->associate($website)->save();

... but I'm not succeeding. And I'm also not sure how to tell the FQDN I'd like

Upvotes: 0

Views: 813

Answers (1)

Magno Alberto
Magno Alberto

Reputation: 668

So easy that I can not even believe it took me 2 days to find the answer, but really their documentation leaves a lot to be desired...

$website = new Website();
$website->managed_by_database_connection = env('DB_CONNECTION','system');

app(WebsiteRepository::class)->create($website);

$hostname = new Hostname();
$hostname->fqdn = 'sub1.domain.local';
app(HostnameRepository::class)->attach($hostname, $website);

app(Environment::class)->tenant($website);

Upvotes: 1

Related Questions