Update Instance model, add entity casts

This commit is contained in:
Daniel Supernault 2024-02-07 02:49:29 -07:00
parent 240e6bbe4f
commit 289cad470b
No known key found for this signature in database
GPG key ID: 23740873EE6F76A1

View file

@ -6,63 +6,77 @@ use Illuminate\Database\Eloquent\Model;
class Instance extends Model class Instance extends Model
{ {
protected $fillable = ['domain', 'banned', 'auto_cw', 'unlisted', 'notes']; protected $casts = [
'last_crawled_at' => 'datetime',
'actors_last_synced_at' => 'datetime',
'notes' => 'array',
'nodeinfo_last_fetched' => 'datetime',
'delivery_next_after' => 'datetime',
];
public function profiles() protected $fillable = [
{ 'domain',
return $this->hasMany(Profile::class, 'domain', 'domain'); 'banned',
} 'auto_cw',
'unlisted',
'notes'
];
public function statuses() public function profiles()
{ {
return $this->hasManyThrough( return $this->hasMany(Profile::class, 'domain', 'domain');
Status::class, }
Profile::class,
'domain',
'profile_id',
'domain',
'id'
);
}
public function reported() public function statuses()
{ {
return $this->hasManyThrough( return $this->hasManyThrough(
Report::class, Status::class,
Profile::class, Profile::class,
'domain', 'domain',
'reported_profile_id', 'profile_id',
'domain', 'domain',
'id' 'id'
); );
} }
public function reports() public function reported()
{ {
return $this->hasManyThrough( return $this->hasManyThrough(
Report::class, Report::class,
Profile::class, Profile::class,
'domain', 'domain',
'profile_id', 'reported_profile_id',
'domain', 'domain',
'id' 'id'
); );
} }
public function media() public function reports()
{ {
return $this->hasManyThrough( return $this->hasManyThrough(
Media::class, Report::class,
Profile::class, Profile::class,
'domain', 'domain',
'profile_id', 'profile_id',
'domain', 'domain',
'id' 'id'
); );
} }
public function getUrl() public function media()
{ {
return url("/i/admin/instances/show/{$this->id}"); return $this->hasManyThrough(
} Media::class,
Profile::class,
'domain',
'profile_id',
'domain',
'id'
);
}
public function getUrl()
{
return url("/i/admin/instances/show/{$this->id}");
}
} }