From 34c1bff186c28667d6cd57e955a0f0d0dcb99c37 Mon Sep 17 00:00:00 2001 From: James Brooks Date: Fri, 11 May 2018 18:02:56 +0100 Subject: [PATCH] Make Taggable trait for simpleness --- app/Models/Component.php | 13 ++----------- app/Models/Incident.php | 13 ++----------- app/Models/Traits/Taggable.php | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 36 insertions(+), 22 deletions(-) create mode 100644 app/Models/Traits/Taggable.php diff --git a/app/Models/Component.php b/app/Models/Component.php index 37a20638..d1cb1436 100644 --- a/app/Models/Component.php +++ b/app/Models/Component.php @@ -14,6 +14,7 @@ namespace CachetHQ\Cachet\Models; use AltThree\Validator\ValidatingTrait; use CachetHQ\Cachet\Models\Traits\SearchableTrait; use CachetHQ\Cachet\Models\Traits\SortableTrait; +use CachetHQ\Cachet\Models\Traits\Taggable; use CachetHQ\Cachet\Presenters\ComponentPresenter; use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Model; @@ -22,7 +23,7 @@ use McCool\LaravelAutoPresenter\HasPresenter; class Component extends Model implements HasPresenter { - use SearchableTrait, SoftDeletes, SortableTrait, ValidatingTrait; + use SearchableTrait, SoftDeletes, SortableTrait, Taggable, ValidatingTrait; /** * List of attributes that have default values. @@ -143,16 +144,6 @@ class Component extends Model implements HasPresenter return $this->morphMany(Meta::class, 'meta'); } - /** - * Get the tags relation. - * - * @return \Illuminate\Database\Eloquent\Relations\MorphMany - */ - public function tags() - { - return $this->morphMany(Taggable::class, 'taggable'); - } - /** * Finds all components by status. * diff --git a/app/Models/Incident.php b/app/Models/Incident.php index 2c40038f..8e41e95b 100644 --- a/app/Models/Incident.php +++ b/app/Models/Incident.php @@ -14,6 +14,7 @@ namespace CachetHQ\Cachet\Models; use AltThree\Validator\ValidatingTrait; use CachetHQ\Cachet\Models\Traits\SearchableTrait; use CachetHQ\Cachet\Models\Traits\SortableTrait; +use CachetHQ\Cachet\Models\Traits\Taggable; use CachetHQ\Cachet\Presenters\IncidentPresenter; use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Model; @@ -29,7 +30,7 @@ use McCool\LaravelAutoPresenter\HasPresenter; */ class Incident extends Model implements HasPresenter { - use SearchableTrait, SoftDeletes, SortableTrait, ValidatingTrait; + use SearchableTrait, SoftDeletes, SortableTrait, Taggable, ValidatingTrait; /** * Status for incident being investigated. @@ -177,16 +178,6 @@ class Incident extends Model implements HasPresenter return $this->morphMany(Meta::class, 'meta'); } - /** - * Get the tags relation. - * - * @return \Illuminate\Database\Eloquent\Relations\MorphMany - */ - public function tags() - { - return $this->morphMany(Taggable::class, 'taggable'); - } - /** * Get the updates relation. * diff --git a/app/Models/Traits/Taggable.php b/app/Models/Traits/Taggable.php new file mode 100644 index 00000000..f7c07a06 --- /dev/null +++ b/app/Models/Traits/Taggable.php @@ -0,0 +1,32 @@ + + */ +trait Taggable +{ + /** + * Get the tags relation. + * + * @return \Illuminate\Database\Eloquent\Relations\MorphMany + */ + public function tags() + { + return $this->morphMany(TaggableModel::class, 'taggable'); + } +}