Make component_tag a polymorphic structure

This commit is contained in:
James Brooks
2018-04-02 17:43:22 +01:00
parent 4b893eeaf5
commit c137e9ab1b
4 changed files with 165 additions and 0 deletions

View File

@@ -54,6 +54,7 @@ class AppServiceProvider extends ServiceProvider
'metrics' => \CachetHQ\Cachet\Models\Metric::class,
'schedules' => \CachetHQ\Cachet\Models\Schedule::class,
'subscriber' => \CachetHQ\Cachet\Models\Subscriber::class,
'tags' => \CachetHQ\Cachet\Models\Tag::class,
]);
}

65
app/Models/Taggable.php Normal file
View File

@@ -0,0 +1,65 @@
<?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;
use Illuminate\Database\Eloquent\Model;
/**
* This is the taggable model class.
*
* @author James Brooks <james@alt-three.com>
*/
class Taggable extends Model
{
/**
* The attributes that should be casted to native types.
*
* @var string[]
*/
protected $casts = [
'id' => 'int',
'tag_id' => 'int',
'taggable_id' => 'int',
'taggable_type' => 'string',
];
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'tag_id',
'taggable_id',
'taggable_type',
];
/**
* Get the tag relation.
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function tag()
{
return $this->belongsTo(Tag::class);
}
/**
* Get the taggable relation.
*
* @return \Illuminate\Database\Eloquent\Relations\MorphTo
*/
public function taggable()
{
return $this->morphTo();
}
}