Rewrite the tags implementation. Closes #391
This commit is contained in:
committed by
Joseph Cohen
parent
65d0e4f5f1
commit
0fecc5dc8a
@@ -85,6 +85,16 @@ class Component extends Model implements TransformableInterface
|
||||
return $this->hasMany('CachetHQ\Cachet\Models\Incident', 'component_id', 'id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Components can have many tags.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
*/
|
||||
public function tags()
|
||||
{
|
||||
return $this->belongsToMany('CachetHQ\Cachet\Models\Tag');
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds all components by status.
|
||||
*
|
||||
@@ -121,6 +131,20 @@ class Component extends Model implements TransformableInterface
|
||||
return trans('cachet.components.status.'.$this->status);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all of the tags on this component.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getTagsListAttribute()
|
||||
{
|
||||
$tags = $this->tags->map(function ($tag) {
|
||||
return $tag->name;
|
||||
});
|
||||
|
||||
return implode(', ', $tags->toArray());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the transformer instance.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user