Instance.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. namespace App;
  3. use Illuminate\Database\Eloquent\Model;
  4. class Instance extends Model
  5. {
  6. protected $casts = [
  7. 'last_crawled_at' => 'datetime',
  8. 'actors_last_synced_at' => 'datetime',
  9. 'notes' => 'array',
  10. 'nodeinfo_last_fetched' => 'datetime',
  11. 'delivery_next_after' => 'datetime',
  12. ];
  13. protected $fillable = [
  14. 'domain',
  15. 'banned',
  16. 'auto_cw',
  17. 'unlisted',
  18. 'notes'
  19. ];
  20. // To get all moderated instances, we need to search where (banned OR unlisted)
  21. public function scopeModerated($query): void {
  22. $query->where(function ($query) {
  23. $query->where('banned', true)->orWhere('unlisted', true);
  24. });
  25. }
  26. public function profiles()
  27. {
  28. return $this->hasMany(Profile::class, 'domain', 'domain');
  29. }
  30. public function statuses()
  31. {
  32. return $this->hasManyThrough(
  33. Status::class,
  34. Profile::class,
  35. 'domain',
  36. 'profile_id',
  37. 'domain',
  38. 'id'
  39. );
  40. }
  41. public function reported()
  42. {
  43. return $this->hasManyThrough(
  44. Report::class,
  45. Profile::class,
  46. 'domain',
  47. 'reported_profile_id',
  48. 'domain',
  49. 'id'
  50. );
  51. }
  52. public function reports()
  53. {
  54. return $this->hasManyThrough(
  55. Report::class,
  56. Profile::class,
  57. 'domain',
  58. 'profile_id',
  59. 'domain',
  60. 'id'
  61. );
  62. }
  63. public function media()
  64. {
  65. return $this->hasManyThrough(
  66. Media::class,
  67. Profile::class,
  68. 'domain',
  69. 'profile_id',
  70. 'domain',
  71. 'id'
  72. );
  73. }
  74. public function getUrl()
  75. {
  76. return url("/i/admin/instances/show/{$this->id}");
  77. }
  78. }