Make Taggable trait for simpleness

This commit is contained in:
James Brooks 2018-05-11 18:02:56 +01:00
parent 23f7d58010
commit 34c1bff186
3 changed files with 36 additions and 22 deletions

View File

@ -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.
*

View File

@ -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.
*

View File

@ -0,0 +1,32 @@
<?php
/*
* This file is part of Cachet.
*
* (c) Alt Three Services Limited
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace CachetHQ\Cachet\Models\Traits;
use CachetHQ\Cachet\Models\Taggable as TaggableModel;
/**
* This is the taggable trait.
*
* @author James Brooks <james@alt-three.com>
*/
trait Taggable
{
/**
* Get the tags relation.
*
* @return \Illuminate\Database\Eloquent\Relations\MorphMany
*/
public function tags()
{
return $this->morphMany(TaggableModel::class, 'taggable');
}
}