Files
m105 72b87ab579 Track and display subdomains under their root domain
Adds sites.root_domain (indexed string, backfilled for existing rows)
computed via a naive "last two labels" heuristic (App\Support\RootDomain)
— good enough for example.com/somesite.es, but wrong for two-part
public suffixes like .co.uk. Doing that correctly needs the Mozilla
Public Suffix List; flagged as a known simplification rather than
built now.

Deliberately not a hard FK: like Backlink.target_domain, a subdomain
can get indexed before its root domain does (or vice versa), so
Site::subdomains()/rootSite() match on the domain string rather than
requiring the relationship to exist at write time.

Site detail page: a root domain shows a paginated "Subdomains"
section (same guest-preview cap as Pages/Backlinks); a subdomain
shows "Subdomain of {root}" linking back, when the root is itself
indexed.

Verified against real data: 21k.ro correctly lists its two known
subdomains (buzau.21k.ro, timisoara.21k.ro), each of which correctly
links back to 21k.ro. Added SubdomainsTest (root lists subdomains,
subdomain links to root, empty state) — full suite (31 tests) passes.
2026-07-25 15:44:12 +03:00

41 lines
1.1 KiB
PHP

<?php
namespace App\Http\Controllers;
use App\Models\Site;
use App\Support\GuestPreview;
use Illuminate\Contracts\View\View;
class SiteController extends Controller
{
public function show(Site $site): View
{
$pages = GuestPreview::paginate($site->pages()->orderBy('url'), 50, 'pages_page');
$backlinks = GuestPreview::paginate(
$site->inboundLinks()->with(['site', 'sitePage'])->latest(),
50,
'backlinks_page'
);
$referringDomainsCount = $site->inboundLinks()->distinct()->count('site_id');
$outboundLinksCount = $site->outboundLinks()->count();
$subdomains = GuestPreview::paginate(
$site->subdomains()->withCount('pages')->orderBy('domain'),
50,
'subdomains_page'
);
return view('sites.show', [
'site' => $site,
'pages' => $pages,
'backlinks' => $backlinks,
'referringDomainsCount' => $referringDomainsCount,
'outboundLinksCount' => $outboundLinksCount,
'subdomains' => $subdomains,
'rootSite' => $site->rootSite(),
]);
}
}