diff --git a/app/AccountInterstitial.php b/app/AccountInterstitial.php index 080c35959..8c6f00dc9 100644 --- a/app/AccountInterstitial.php +++ b/app/AccountInterstitial.php @@ -6,18 +6,16 @@ use Illuminate\Database\Eloquent\Model; class AccountInterstitial extends Model { - /** - * The attributes that should be mutated to dates. - * - * @var array - */ - protected $casts = [ - 'read_at' => 'datetime', - 'appeal_requested_at' => 'datetime', - ]; - public const JSON_MESSAGE = 'Please use web browser to proceed.'; + protected function casts(): array + { + return [ + 'read_at' => 'datetime', + 'appeal_requested_at' => 'datetime', + ]; + } + public function user() { return $this->belongsTo(User::class); diff --git a/app/Activity.php b/app/Activity.php index 92e04cc72..a9aea33d1 100644 --- a/app/Activity.php +++ b/app/Activity.php @@ -6,12 +6,15 @@ use Illuminate\Database\Eloquent\Model; class Activity extends Model { - protected $casts = [ - 'processed_at' => 'datetime', - ]; - protected $fillable = ['data', 'to_id', 'from_id', 'object_type']; + protected function casts(): array + { + return [ + 'processed_at' => 'datetime', + ]; + } + public function toProfile() { return $this->belongsTo(Profile::class, 'to_id'); diff --git a/app/Avatar.php b/app/Avatar.php index 9899ffe22..15d719bf4 100644 --- a/app/Avatar.php +++ b/app/Avatar.php @@ -9,19 +9,17 @@ class Avatar extends Model { use SoftDeletes; - /** - * The attributes that should be mutated to dates. - * - * @var array - */ - protected $casts = [ - 'deleted_at' => 'datetime', - 'last_fetched_at' => 'datetime', - 'last_processed_at' => 'datetime', - ]; - protected $guarded = []; + protected function casts(): array + { + return [ + 'deleted_at' => 'datetime', + 'last_fetched_at' => 'datetime', + 'last_processed_at' => 'datetime', + ]; + } + protected $visible = [ 'id', 'profile_id', diff --git a/app/Contact.php b/app/Contact.php index 2239af7d8..4d6319a5a 100644 --- a/app/Contact.php +++ b/app/Contact.php @@ -7,9 +7,12 @@ use Illuminate\Support\Str; class Contact extends Model { - protected $casts = [ - 'responded_at' => 'datetime', - ]; + protected function casts(): array + { + return [ + 'responded_at' => 'datetime', + ]; + } public function user() { diff --git a/app/FollowRequest.php b/app/FollowRequest.php index 15cac3411..a8c0302e1 100644 --- a/app/FollowRequest.php +++ b/app/FollowRequest.php @@ -21,9 +21,12 @@ class FollowRequest extends Model { protected $fillable = ['follower_id', 'following_id', 'activity', 'handled_at']; - protected $casts = [ - 'activity' => 'array', - ]; + protected function casts(): array + { + return [ + 'activity' => 'array', + ]; + } public function actor() { diff --git a/app/Instance.php b/app/Instance.php index b52f34af7..a86312be4 100644 --- a/app/Instance.php +++ b/app/Instance.php @@ -6,14 +6,6 @@ use Illuminate\Database\Eloquent\Model; class Instance extends Model { - protected $casts = [ - 'last_crawled_at' => 'datetime', - 'actors_last_synced_at' => 'datetime', - 'notes' => 'array', - 'nodeinfo_last_fetched' => 'datetime', - 'delivery_next_after' => 'datetime', - ]; - protected $fillable = [ 'domain', 'banned', @@ -22,6 +14,17 @@ class Instance extends Model 'notes', ]; + protected function casts(): array + { + return [ + 'last_crawled_at' => 'datetime', + 'actors_last_synced_at' => 'datetime', + 'notes' => 'array', + 'nodeinfo_last_fetched' => 'datetime', + 'delivery_next_after' => 'datetime', + ]; + } + // To get all moderated instances, we need to search where (banned OR unlisted) public function scopeModerated($query): void { diff --git a/app/Like.php b/app/Like.php index 05c1836ce..47d679c55 100644 --- a/app/Like.php +++ b/app/Like.php @@ -11,17 +11,15 @@ class Like extends Model const MAX_PER_DAY = 1500; - /** - * The attributes that should be mutated to dates. - * - * @var array - */ - protected $casts = [ - 'deleted_at' => 'datetime', - ]; - protected $fillable = ['profile_id', 'status_id', 'status_profile_id']; + protected function casts(): array + { + return [ + 'deleted_at' => 'datetime', + ]; + } + public function actor() { return $this->belongsTo(Profile::class, 'profile_id', 'id'); diff --git a/app/Media.php b/app/Media.php index fd62653f0..939a74f6d 100644 --- a/app/Media.php +++ b/app/Media.php @@ -12,18 +12,16 @@ class Media extends Model { use SoftDeletes; - /** - * The attributes that should be mutated to dates. - * - * @var array - */ protected $guarded = []; - protected $casts = [ - 'srcset' => 'array', - 'deleted_at' => 'datetime', - 'skip_optimize' => 'boolean', - ]; + protected function casts(): array + { + return [ + 'srcset' => 'array', + 'deleted_at' => 'datetime', + 'skip_optimize' => 'boolean', + ]; + } public function status() { diff --git a/app/Mention.php b/app/Mention.php index 242ecd81f..fc97fda04 100644 --- a/app/Mention.php +++ b/app/Mention.php @@ -9,17 +9,15 @@ class Mention extends Model { use SoftDeletes; - /** - * The attributes that should be mutated to dates. - * - * @var array - */ - protected $casts = [ - 'deleted_at' => 'datetime', - ]; - protected $guarded = []; + protected function casts(): array + { + return [ + 'deleted_at' => 'datetime', + ]; + } + public function profile() { return $this->belongsTo(Profile::class, 'profile_id', 'id'); diff --git a/app/Models/AdminInvite.php b/app/Models/AdminInvite.php index 2dfb87a51..2101be5d5 100644 --- a/app/Models/AdminInvite.php +++ b/app/Models/AdminInvite.php @@ -7,11 +7,6 @@ use Illuminate\Support\Str; class AdminInvite extends Model { - protected $casts = [ - 'used_by' => 'array', - 'expires_at' => 'datetime', - ]; - protected $fillable = [ 'name', 'description', @@ -23,6 +18,14 @@ class AdminInvite extends Model 'admin_user_id', ]; + protected function casts(): array + { + return [ + 'used_by' => 'array', + 'expires_at' => 'datetime', + ]; + } + protected static function booted(): void { static::creating(function (AdminInvite $invite) { diff --git a/app/Models/AdminShadowFilter.php b/app/Models/AdminShadowFilter.php index 8e0e5499f..6edc1cfa3 100644 --- a/app/Models/AdminShadowFilter.php +++ b/app/Models/AdminShadowFilter.php @@ -13,9 +13,12 @@ class AdminShadowFilter extends Model protected $guarded = []; - protected $casts = [ - 'created_at' => 'datetime', - ]; + protected function casts(): array + { + return [ + 'created_at' => 'datetime', + ]; + } public function account() { diff --git a/app/Models/CuratedRegister.php b/app/Models/CuratedRegister.php index 062408230..1c126ff06 100644 --- a/app/Models/CuratedRegister.php +++ b/app/Models/CuratedRegister.php @@ -13,18 +13,21 @@ class CuratedRegister extends Model 'user_has_responded', ]; - protected $casts = [ - 'autofollow_account_ids' => 'array', - 'admin_notes' => 'array', - 'email_verified_at' => 'datetime', - 'admin_notified_at' => 'datetime', - 'action_taken_at' => 'datetime', - 'user_has_responded' => 'boolean', - 'is_awaiting_more_info' => 'boolean', - 'is_accepted' => 'boolean', - 'is_rejected' => 'boolean', - 'is_closed' => 'boolean', - ]; + protected function casts(): array + { + return [ + 'autofollow_account_ids' => 'array', + 'admin_notes' => 'array', + 'email_verified_at' => 'datetime', + 'admin_notified_at' => 'datetime', + 'action_taken_at' => 'datetime', + 'user_has_responded' => 'boolean', + 'is_awaiting_more_info' => 'boolean', + 'is_accepted' => 'boolean', + 'is_rejected' => 'boolean', + 'is_closed' => 'boolean', + ]; + } public function adminStatusLabel() { diff --git a/app/Models/CuratedRegisterActivity.php b/app/Models/CuratedRegisterActivity.php index d7d6aee0f..247fc474b 100644 --- a/app/Models/CuratedRegisterActivity.php +++ b/app/Models/CuratedRegisterActivity.php @@ -11,11 +11,14 @@ class CuratedRegisterActivity extends Model protected $guarded = []; - protected $casts = [ - 'metadata' => 'array', - 'admin_notified_at' => 'datetime', - 'action_taken_at' => 'datetime', - ]; + protected function casts(): array + { + return [ + 'metadata' => 'array', + 'admin_notified_at' => 'datetime', + 'action_taken_at' => 'datetime', + ]; + } public function application() { diff --git a/app/Models/CuratedRegisterTemplate.php b/app/Models/CuratedRegisterTemplate.php index a5def0cef..c0505ebe0 100644 --- a/app/Models/CuratedRegisterTemplate.php +++ b/app/Models/CuratedRegisterTemplate.php @@ -13,7 +13,10 @@ class CuratedRegisterTemplate extends Model 'name', 'description', 'content', 'is_active', 'order', ]; - protected $casts = [ - 'is_active' => 'boolean', - ]; + protected function casts(): array + { + return [ + 'is_active' => 'boolean', + ]; + } } diff --git a/app/Models/CustomFilter.php b/app/Models/CustomFilter.php index dd0019033..98e2d9edc 100644 --- a/app/Models/CustomFilter.php +++ b/app/Models/CustomFilter.php @@ -14,15 +14,18 @@ class CustomFilter extends Model 'title', 'phrase', 'context', 'expires_at', 'action', 'profile_id', ]; - protected $casts = [ - 'id' => 'string', - 'context' => 'array', - 'expires_at' => 'datetime', - 'action' => 'integer', - ]; - protected $guarded = ['shouldInvalidateCache']; + protected function casts(): array + { + return [ + 'id' => 'string', + 'context' => 'array', + 'expires_at' => 'datetime', + 'action' => 'integer', + ]; + } + const VALID_CONTEXTS = [ 'home', 'notifications', diff --git a/app/Models/CustomFilterKeyword.php b/app/Models/CustomFilterKeyword.php index a6dee3e21..a17123ff4 100644 --- a/app/Models/CustomFilterKeyword.php +++ b/app/Models/CustomFilterKeyword.php @@ -10,9 +10,12 @@ class CustomFilterKeyword extends Model 'keyword', 'whole_word', 'custom_filter_id', ]; - protected $casts = [ - 'whole_word' => 'boolean', - ]; + protected function casts(): array + { + return [ + 'whole_word' => 'boolean', + ]; + } public function customFilter() { diff --git a/app/Models/Group.php b/app/Models/Group.php index c7f711d87..abc2a7b42 100644 --- a/app/Models/Group.php +++ b/app/Models/Group.php @@ -33,9 +33,12 @@ class Group extends Model */ public $incrementing = false; - protected $casts = [ - 'metadata' => 'json', - ]; + protected function casts(): array + { + return [ + 'metadata' => 'json', + ]; + } public function url() { diff --git a/app/Models/GroupInteraction.php b/app/Models/GroupInteraction.php index 06e3704e7..77aa9fd1a 100644 --- a/app/Models/GroupInteraction.php +++ b/app/Models/GroupInteraction.php @@ -9,7 +9,10 @@ class GroupInteraction extends Model { use HasFactory; - protected $casts = [ - 'metadata' => 'array', - ]; + protected function casts(): array + { + return [ + 'metadata' => 'array', + ]; + } } diff --git a/app/Models/GroupLimit.php b/app/Models/GroupLimit.php index d89002b95..682280b40 100644 --- a/app/Models/GroupLimit.php +++ b/app/Models/GroupLimit.php @@ -9,13 +9,16 @@ class GroupLimit extends Model { use HasFactory; - protected $casts = [ - 'limits' => 'json', - 'metadata' => 'json', - ]; - protected $fillable = [ 'profile_id', 'group_id', ]; + + protected function casts(): array + { + return [ + 'limits' => 'json', + 'metadata' => 'json', + ]; + } } diff --git a/app/Models/HashtagRelated.php b/app/Models/HashtagRelated.php index bbaa1c06c..6eb8c58b8 100644 --- a/app/Models/HashtagRelated.php +++ b/app/Models/HashtagRelated.php @@ -11,14 +11,12 @@ class HashtagRelated extends Model protected $guarded = []; - /** - * The attributes that should be mutated to dates and other custom formats. - * - * @var array - */ - protected $casts = [ - 'related_tags' => 'array', - 'last_calculated_at' => 'datetime', - 'last_moderated_at' => 'datetime', - ]; + protected function casts(): array + { + return [ + 'related_tags' => 'array', + 'last_calculated_at' => 'datetime', + 'last_moderated_at' => 'datetime', + ]; + } } diff --git a/app/Models/ImportPost.php b/app/Models/ImportPost.php index f8a3f2b50..e2d17d368 100644 --- a/app/Models/ImportPost.php +++ b/app/Models/ImportPost.php @@ -10,11 +10,14 @@ class ImportPost extends Model { use HasFactory; - protected $casts = [ - 'media' => 'array', - 'creation_date' => 'datetime', - 'metadata' => 'json', - ]; + protected function casts(): array + { + return [ + 'media' => 'array', + 'creation_date' => 'datetime', + 'metadata' => 'json', + ]; + } public function status() { diff --git a/app/Models/ParentalControls.php b/app/Models/ParentalControls.php index 8054a66f1..473a70d44 100644 --- a/app/Models/ParentalControls.php +++ b/app/Models/ParentalControls.php @@ -26,14 +26,17 @@ class ParentalControls extends Model { use HasFactory, SoftDeletes; - protected $casts = [ - 'permissions' => 'array', - 'email_sent_at' => 'datetime', - 'email_verified_at' => 'datetime', - ]; - protected $guarded = []; + protected function casts(): array + { + return [ + 'permissions' => 'array', + 'email_sent_at' => 'datetime', + 'email_verified_at' => 'datetime', + ]; + } + public function parent() { return $this->belongsTo(User::class, 'parent_id'); diff --git a/app/Models/Poll.php b/app/Models/Poll.php index eeb861eab..10868c26f 100644 --- a/app/Models/Poll.php +++ b/app/Models/Poll.php @@ -17,11 +17,14 @@ class Poll extends Model */ public $incrementing = false; - protected $casts = [ - 'poll_options' => 'array', - 'cached_tallies' => 'array', - 'expires_at' => 'datetime', - ]; + protected function casts(): array + { + return [ + 'poll_options' => 'array', + 'cached_tallies' => 'array', + 'expires_at' => 'datetime', + ]; + } public function votes() { diff --git a/app/Models/Portfolio.php b/app/Models/Portfolio.php index c7bb16608..cf49b04fa 100644 --- a/app/Models/Portfolio.php +++ b/app/Models/Portfolio.php @@ -24,9 +24,12 @@ class Portfolio extends Model 'profile_source', ]; - protected $casts = [ - 'metadata' => 'json', - ]; + protected function casts(): array + { + return [ + 'metadata' => 'json', + ]; + } public function url($suffix = '') { diff --git a/app/Models/RemoteAuth.php b/app/Models/RemoteAuth.php index 571ed21bf..35ded76bf 100644 --- a/app/Models/RemoteAuth.php +++ b/app/Models/RemoteAuth.php @@ -11,9 +11,12 @@ class RemoteAuth extends Model protected $guarded = []; - protected $casts = [ - 'verify_credentials' => 'array', - 'last_successful_login_at' => 'datetime', - 'last_verify_credentials_at' => 'datetime', - ]; + protected function casts(): array + { + return [ + 'verify_credentials' => 'array', + 'last_successful_login_at' => 'datetime', + 'last_verify_credentials_at' => 'datetime', + ]; + } } diff --git a/app/Models/RemoteReport.php b/app/Models/RemoteReport.php index 65ec40e06..d5ad40b3f 100644 --- a/app/Models/RemoteReport.php +++ b/app/Models/RemoteReport.php @@ -9,9 +9,12 @@ class RemoteReport extends Model { use HasFactory; - protected $casts = [ - 'status_ids' => 'array', - 'action_taken_meta' => 'array', - 'report_meta' => 'array', - ]; + protected function casts(): array + { + return [ + 'status_ids' => 'array', + 'action_taken_meta' => 'array', + 'report_meta' => 'array', + ]; + } } diff --git a/app/Models/StatusEdit.php b/app/Models/StatusEdit.php index 4b36f94bf..b856414c0 100644 --- a/app/Models/StatusEdit.php +++ b/app/Models/StatusEdit.php @@ -9,11 +9,14 @@ class StatusEdit extends Model { use HasFactory; - protected $casts = [ - 'ordered_media_attachment_ids' => 'array', - 'media_descriptions' => 'array', - 'poll_options' => 'array', - ]; - protected $guarded = []; + + protected function casts(): array + { + return [ + 'ordered_media_attachment_ids' => 'array', + 'media_descriptions' => 'array', + 'poll_options' => 'array', + ]; + } } diff --git a/app/Models/UserAppSettings.php b/app/Models/UserAppSettings.php index 572aa0033..5d2c4d2dc 100644 --- a/app/Models/UserAppSettings.php +++ b/app/Models/UserAppSettings.php @@ -12,16 +12,19 @@ class UserAppSettings extends Model protected $guarded = []; - protected $casts = [ - 'common' => 'json', - 'custom' => 'json', - 'common.timelines.show_public' => 'boolean', - 'common.timelines.show_network' => 'boolean', - 'common.timelines.hide_likes_shares' => 'boolean', - 'common.media.hide_public_behind_cw' => 'boolean', - 'common.media.always_show_cw' => 'boolean', - 'common.media.show_alt_text' => 'boolean', - ]; + protected function casts(): array + { + return [ + 'common' => 'json', + 'custom' => 'json', + 'common.timelines.show_public' => 'boolean', + 'common.timelines.show_network' => 'boolean', + 'common.timelines.hide_likes_shares' => 'boolean', + 'common.media.hide_public_behind_cw' => 'boolean', + 'common.media.always_show_cw' => 'boolean', + 'common.media.show_alt_text' => 'boolean', + ]; + } public function user() { diff --git a/app/Models/UserEmailForgot.php b/app/Models/UserEmailForgot.php index 9e549aff4..d36f3b514 100644 --- a/app/Models/UserEmailForgot.php +++ b/app/Models/UserEmailForgot.php @@ -11,7 +11,10 @@ class UserEmailForgot extends Model protected $guarded = []; - protected $casts = [ - 'email_sent_at' => 'datetime', - ]; + protected function casts(): array + { + return [ + 'email_sent_at' => 'datetime', + ]; + } } diff --git a/app/Models/UserRoles.php b/app/Models/UserRoles.php index c8d199865..b716fe83e 100644 --- a/app/Models/UserRoles.php +++ b/app/Models/UserRoles.php @@ -12,10 +12,13 @@ class UserRoles extends Model protected $guarded = []; - protected $casts = [ - 'roles' => 'array', - 'meta' => 'array', - ]; + protected function casts(): array + { + return [ + 'roles' => 'array', + 'meta' => 'array', + ]; + } public function user() { diff --git a/app/Newsroom.php b/app/Newsroom.php index 8fa551d4a..88178c9ad 100644 --- a/app/Newsroom.php +++ b/app/Newsroom.php @@ -10,9 +10,12 @@ class Newsroom extends Model protected $fillable = ['title']; - protected $casts = [ - 'published_at' => 'datetime', - ]; + protected function casts(): array + { + return [ + 'published_at' => 'datetime', + ]; + } public function permalink() { diff --git a/app/Notification.php b/app/Notification.php index a107c4550..0fedefb69 100644 --- a/app/Notification.php +++ b/app/Notification.php @@ -9,17 +9,15 @@ class Notification extends Model { use SoftDeletes; - /** - * The attributes that should be mutated to dates. - * - * @var array - */ - protected $casts = [ - 'deleted_at' => 'datetime', - ]; - protected $guarded = []; + protected function casts(): array + { + return [ + 'deleted_at' => 'datetime', + ]; + } + public function actor() { return $this->belongsTo(Profile::class, 'actor_id', 'id'); diff --git a/app/Profile.php b/app/Profile.php index 34c304f58..0e86c7d2f 100644 --- a/app/Profile.php +++ b/app/Profile.php @@ -41,18 +41,21 @@ class Profile extends Model */ public $incrementing = false; - protected $casts = [ - 'deleted_at' => 'datetime', - 'last_fetched_at' => 'datetime', - 'last_status_at' => 'datetime', - ]; - protected $hidden = ['private_key']; protected $visible = ['id', 'user_id', 'username', 'name']; protected $guarded = []; + protected function casts(): array + { + return [ + 'deleted_at' => 'datetime', + 'last_fetched_at' => 'datetime', + 'last_status_at' => 'datetime', + ]; + } + public function user() { return $this->belongsTo(User::class); diff --git a/app/Report.php b/app/Report.php index aad7fc7d6..77d2dad48 100644 --- a/app/Report.php +++ b/app/Report.php @@ -6,12 +6,15 @@ use Illuminate\Database\Eloquent\Model; class Report extends Model { - protected $casts = [ - 'admin_seen' => 'datetime', - ]; - protected $guarded = []; + protected function casts(): array + { + return [ + 'admin_seen' => 'datetime', + ]; + } + public function url() { return url('/i/admin/reports/show/'.$this->id); diff --git a/app/Status.php b/app/Status.php index 1204879c2..f262af905 100644 --- a/app/Status.php +++ b/app/Status.php @@ -51,18 +51,16 @@ class Status extends Model */ public $incrementing = false; - /** - * The attributes that should be mutated to dates. - * - * @var array - */ - protected $casts = [ - 'deleted_at' => 'datetime', - 'edited_at' => 'datetime', - ]; - protected $guarded = []; + protected function casts(): array + { + return [ + 'deleted_at' => 'datetime', + 'edited_at' => 'datetime', + ]; + } + const STATUS_TYPES = [ 'text', 'photo', diff --git a/app/Story.php b/app/Story.php index ce8113a79..075be623f 100644 --- a/app/Story.php +++ b/app/Story.php @@ -32,18 +32,21 @@ class Story extends Model */ public $incrementing = false; - protected $casts = [ - 'story' => 'json', - 'expires_at' => 'datetime', - 'view_count' => 'integer', - ]; - protected $fillable = ['profile_id', 'view_count']; protected $visible = ['id']; protected $hidden = ['json']; + protected function casts(): array + { + return [ + 'story' => 'json', + 'expires_at' => 'datetime', + 'view_count' => 'integer', + ]; + } + public function profile() { return $this->belongsTo(Profile::class); diff --git a/app/StoryItem.php b/app/StoryItem.php index fcc88bfce..a442587bd 100644 --- a/app/StoryItem.php +++ b/app/StoryItem.php @@ -25,17 +25,15 @@ class StoryItem extends Model */ public $incrementing = false; - /** - * The attributes that should be mutated to dates. - * - * @var array - */ - protected $casts = [ - 'expires_at' => 'datetime', - ]; - protected $visible = ['id']; + protected function casts(): array + { + return [ + 'expires_at' => 'datetime', + ]; + } + public function story() { return $this->belongsTo(Story::class); diff --git a/app/UserSetting.php b/app/UserSetting.php index 09f4bc872..91744eafb 100644 --- a/app/UserSetting.php +++ b/app/UserSetting.php @@ -8,8 +8,11 @@ class UserSetting extends Model { protected $fillable = ['user_id']; - protected $casts = [ - 'compose_settings' => 'json', - 'other' => 'json', - ]; + protected function casts(): array + { + return [ + 'compose_settings' => 'json', + 'other' => 'json', + ]; + } }