diff --git a/app/Models/Component.php b/app/Models/Component.php index 1b7901ac7ce8..5f37c0783cb1 100644 --- a/app/Models/Component.php +++ b/app/Models/Component.php @@ -12,6 +12,7 @@ namespace CachetHQ\Cachet\Models; use AltThree\Validator\ValidatingTrait; +use CachetHQ\Cachet\Models\Traits\HasMeta; use CachetHQ\Cachet\Models\Traits\HasTags; use CachetHQ\Cachet\Models\Traits\SearchableTrait; use CachetHQ\Cachet\Models\Traits\SortableTrait; @@ -23,7 +24,12 @@ class Component extends Model implements HasPresenter { - use HasTags, SearchableTrait, SoftDeletes, SortableTrait, ValidatingTrait; + use HasTags, + HasMeta, + SearchableTrait, + SoftDeletes, + SortableTrait, + ValidatingTrait; /** * List of attributes that have default values. @@ -134,16 +140,6 @@ public function incidents() return $this->hasMany(Incident::class, 'component_id', 'id'); } - /** - * Get the meta relation. - * - * @return \Illuminate\Database\Eloquent\Relations\MorphMany - */ - public function meta() - { - return $this->morphMany(Meta::class, 'meta'); - } - /** * Finds all components by status. * diff --git a/app/Models/Incident.php b/app/Models/Incident.php index a91320aa0cd9..772e71c8f9e6 100644 --- a/app/Models/Incident.php +++ b/app/Models/Incident.php @@ -12,6 +12,7 @@ namespace CachetHQ\Cachet\Models; use AltThree\Validator\ValidatingTrait; +use CachetHQ\Cachet\Models\Traits\HasMeta; use CachetHQ\Cachet\Models\Traits\HasTags; use CachetHQ\Cachet\Models\Traits\SearchableTrait; use CachetHQ\Cachet\Models\Traits\SortableTrait; @@ -30,7 +31,12 @@ */ class Incident extends Model implements HasPresenter { - use HasTags, SearchableTrait, SoftDeletes, SortableTrait, ValidatingTrait; + use HasMeta, + HasTags, + SearchableTrait, + SoftDeletes, + SortableTrait, + ValidatingTrait; /** * Status for incident being investigated. @@ -181,16 +187,6 @@ public function component() return $this->belongsTo(Component::class, 'component_id', 'id'); } - /** - * Get all of the meta relation. - * - * @return \Illuminate\Database\Eloquent\Relations\MorphMany - */ - public function meta() - { - return $this->morphMany(Meta::class, 'meta'); - } - /** * Get the updates relation. * diff --git a/app/Models/Metric.php b/app/Models/Metric.php index 9f0ace3908fd..8b5bc2d629c3 100644 --- a/app/Models/Metric.php +++ b/app/Models/Metric.php @@ -13,6 +13,7 @@ use AltThree\Validator\ValidatingTrait; use AltThree\Validator\ValidationException; +use CachetHQ\Cachet\Models\Traits\HasMeta; use CachetHQ\Cachet\Models\Traits\SortableTrait; use CachetHQ\Cachet\Presenters\MetricPresenter; use Illuminate\Database\Eloquent\Builder; @@ -22,7 +23,9 @@ class Metric extends Model implements HasPresenter { - use SortableTrait, ValidatingTrait; + use HasMeta, + SortableTrait, + ValidatingTrait; /** * The calculation type of sum. @@ -165,16 +168,6 @@ public static function boot() }); } - /** - * Get the meta relation. - * - * @return \Illuminate\Database\Eloquent\Relations\MorphMany - */ - public function meta() - { - return $this->morphMany(Meta::class, 'meta'); - } - /** * Get the points relation. * diff --git a/app/Models/Schedule.php b/app/Models/Schedule.php index 3f857cbd84d8..6244820c3bb4 100644 --- a/app/Models/Schedule.php +++ b/app/Models/Schedule.php @@ -12,6 +12,7 @@ namespace CachetHQ\Cachet\Models; use AltThree\Validator\ValidatingTrait; +use CachetHQ\Cachet\Models\Traits\HasMeta; use CachetHQ\Cachet\Models\Traits\SearchableTrait; use CachetHQ\Cachet\Models\Traits\SortableTrait; use CachetHQ\Cachet\Presenters\SchedulePresenter; @@ -28,7 +29,11 @@ */ class Schedule extends Model implements HasPresenter { - use SearchableTrait, SoftDeletes, SortableTrait, ValidatingTrait; + use HasMeta, + SearchableTrait, + SoftDeletes, + SortableTrait, + ValidatingTrait; /** * The upcoming status. @@ -143,16 +148,6 @@ public function components() return $this->hasMany(ScheduleComponent::class); } - /** - * Get the meta relation. - * - * @return \Illuminate\Database\Eloquent\Relations\MorphMany - */ - public function meta() - { - return $this->morphMany(Meta::class, 'meta'); - } - /** * Scope schedules that are in progress. * diff --git a/app/Models/Subscriber.php b/app/Models/Subscriber.php index bfab209c5388..74b473d44921 100644 --- a/app/Models/Subscriber.php +++ b/app/Models/Subscriber.php @@ -12,6 +12,7 @@ namespace CachetHQ\Cachet\Models; use AltThree\Validator\ValidatingTrait; +use CachetHQ\Cachet\Models\Traits\HasMeta; use CachetHQ\Cachet\Presenters\SubscriberPresenter; use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Model; @@ -28,7 +29,9 @@ */ class Subscriber extends Model implements HasPresenter { - use Notifiable, ValidatingTrait; + use HasMeta, + Notifiable, + ValidatingTrait; /** * The attributes that should be casted to native types. @@ -91,16 +94,6 @@ public static function boot() }); } - /** - * Get the meta relation. - * - * @return \Illuminate\Database\Eloquent\Relations\MorphMany - */ - public function meta() - { - return $this->morphMany(Meta::class, 'meta'); - } - /** * Get the subscriptions relation. * diff --git a/app/Models/Traits/HasMeta.php b/app/Models/Traits/HasMeta.php new file mode 100644 index 000000000000..3571cf0a7e65 --- /dev/null +++ b/app/Models/Traits/HasMeta.php @@ -0,0 +1,32 @@ + + */ +trait HasMeta +{ + /** + * Get the meta relation. + * + * @return \Illuminate\Database\Eloquent\Relations\MorphMany + */ + public function meta() + { + return $this->morphMany(Meta::class, 'meta'); + } +}