1. Go to this page and download the library: Download socialdept/tenant-domains library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
socialdept / tenant-domains example snippets
use SocialDept\TenantDomains\Facades\TenantDomains;
$domain = $publication->domains()->create(['domain' => 'blog.example.com']);
TenantDomains::ensureDelegationId($domain);
// Everything the tenant has to create, ready to render.
$instructions = TenantDomains::instructionsFor($domain)->toArray();
// ['type' => 'CNAME', 'name' => 'blog', 'value' => 'to.yourapp.com']
// ['type' => 'TXT', 'name' => '_verify.blog', 'value' => 'verification=…']
// ['type' => 'CNAME', 'name' => '_acme-challenge.blog','value' => 'k7m2q9.acme.yourapp.com']
if (TenantDomains::verifyOwnership($domain) && TenantDomains::verifyRouting($domain)->verified) {
TenantDomains::publish($domain); // the edge now serves it and gets a certificate
}
// A different label under your own domain
'cname_target' => 'ingress.{platform}',
// An existing load balancer on a completely separate domain
'cname_target' => 'lb-7a2.eu-west.example.net',
// A CDN hostname you already publish
'cname_target' => 'customers.yourcdn.example',
use SocialDept\TenantDomains\Contracts\ProvidesOwnershipToken;
class Publication extends Model implements ProvidesOwnershipToken
{
public function domainOwnershipToken(): string
{
return $this->domain_token;
}
}
use SocialDept\TenantDomains\Models\Concerns\IsCustomDomain;
use Stancl\Tenancy\Database\Models\Domain as BaseDomain;
class Domain extends BaseDomain
{
use IsCustomDomain;
protected function casts(): array
{
return [...parent::casts(), ...$this->customDomainCasts()];
}
}
bash
php artisan vendor:publish --tag=tenant-domains-config
# A fresh domains table...
php artisan vendor:publish --tag=tenant-domains-migrations
# ...or, if you already have one (stancl/tenancy does), just the extra columns:
php artisan vendor:publish --tag=tenant-domains-migrations-columns
php artisan migrate
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.