2026-07-20 00:04:45 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
|
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
|
|
|
|
|
|
|
|
class Site extends Model
|
|
|
|
|
{
|
|
|
|
|
protected $fillable = [
|
|
|
|
|
'collection',
|
|
|
|
|
'domain',
|
2026-07-25 15:44:12 +03:00
|
|
|
'root_domain',
|
2026-07-20 00:04:45 +03:00
|
|
|
'url',
|
|
|
|
|
'title',
|
|
|
|
|
'description',
|
|
|
|
|
'keywords',
|
2026-07-22 22:14:40 +03:00
|
|
|
'server',
|
|
|
|
|
'powered_by',
|
|
|
|
|
'generator',
|
2026-07-20 00:04:45 +03:00
|
|
|
];
|
|
|
|
|
|
|
|
|
|
public function pages(): HasMany
|
|
|
|
|
{
|
|
|
|
|
return $this->hasMany(SitePage::class);
|
|
|
|
|
}
|
2026-07-22 21:29:11 +03:00
|
|
|
|
|
|
|
|
/** Links this site's pages make out to other domains. */
|
|
|
|
|
public function outboundLinks(): HasMany
|
|
|
|
|
{
|
|
|
|
|
return $this->hasMany(Backlink::class);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Backlinks pointing at this site, i.e. rows recorded against its domain as the target. */
|
|
|
|
|
public function inboundLinks(): HasMany
|
|
|
|
|
{
|
|
|
|
|
return $this->hasMany(Backlink::class, 'target_domain', 'domain');
|
|
|
|
|
}
|
2026-07-25 15:44:12 +03:00
|
|
|
|
|
|
|
|
/** Other indexed sites whose root domain is this site's domain, e.g. blog.example.com under example.com. */
|
|
|
|
|
public function subdomains(): HasMany
|
|
|
|
|
{
|
|
|
|
|
return $this->hasMany(Site::class, 'root_domain', 'domain')->where('id', '!=', $this->id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** The root-domain Site this one is a subdomain of, if it's indexed and if this site even is a subdomain. */
|
|
|
|
|
public function rootSite(): ?Site
|
|
|
|
|
{
|
|
|
|
|
if ($this->domain === $this->root_domain) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return static::where('domain', $this->root_domain)->first();
|
|
|
|
|
}
|
2026-07-20 00:04:45 +03:00
|
|
|
}
|