Move meta relation into trait

This commit is contained in:
James Brooks 2019-02-18 21:56:25 +00:00
parent 827822e22e
commit 88571d7e8f
6 changed files with 60 additions and 55 deletions

View File

@ -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 @@ use McCool\LaravelAutoPresenter\HasPresenter;
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 @@ class Component extends Model implements HasPresenter
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.
*

View File

@ -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 @@ use McCool\LaravelAutoPresenter\HasPresenter;
*/
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 @@ class Incident extends Model implements HasPresenter
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.
*

View File

@ -13,6 +13,7 @@ namespace CachetHQ\Cachet\Models;
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 @@ use McCool\LaravelAutoPresenter\HasPresenter;
class Metric extends Model implements HasPresenter
{
use SortableTrait, ValidatingTrait;
use HasMeta,
SortableTrait,
ValidatingTrait;
/**
* The calculation type of sum.
@ -165,16 +168,6 @@ class Metric extends Model implements HasPresenter
});
}
/**
* Get the meta relation.
*
* @return \Illuminate\Database\Eloquent\Relations\MorphMany
*/
public function meta()
{
return $this->morphMany(Meta::class, 'meta');
}
/**
* Get the points relation.
*

View File

@ -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 @@ use McCool\LaravelAutoPresenter\HasPresenter;
*/
class Schedule extends Model implements HasPresenter
{
use SearchableTrait, SoftDeletes, SortableTrait, ValidatingTrait;
use HasMeta,
SearchableTrait,
SoftDeletes,
SortableTrait,
ValidatingTrait;
/**
* The upcoming status.
@ -143,16 +148,6 @@ class Schedule extends Model implements HasPresenter
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.
*

View File

@ -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 @@ use McCool\LaravelAutoPresenter\HasPresenter;
*/
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 @@ class Subscriber extends Model implements HasPresenter
});
}
/**
* Get the meta relation.
*
* @return \Illuminate\Database\Eloquent\Relations\MorphMany
*/
public function meta()
{
return $this->morphMany(Meta::class, 'meta');
}
/**
* Get the subscriptions 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\Meta;
/**
* This is the has meta trait.
*
* @author James Brooks <james@alt-three.com>
*/
trait HasMeta
{
/**
* Get the meta relation.
*
* @return \Illuminate\Database\Eloquent\Relations\MorphMany
*/
public function meta()
{
return $this->morphMany(Meta::class, 'meta');
}
}