Make component_tag a polymorphic structure
This commit is contained in:
@@ -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
65
app/Models/Taggable.php
Normal 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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user