CustomAttribute   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
eloc 14
c 1
b 0
f 0
dl 0
loc 33
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A model() 0 3 1
A dynamicAttribute() 0 3 1
1
<?php
2
3
namespace SimpleCMS\DynamicUnit\Models;
4
5
use Spatie\MediaLibrary\HasMedia;
6
use Illuminate\Database\Eloquent\Model;
7
use SimpleCMS\Framework\Traits\MediaAttributeTrait;
8
use Spatie\MediaLibrary\MediaCollections\Models\Media;
9
use Illuminate\Database\Eloquent\Factories\HasFactory;
10
11
/**
12
 * DynamicAttribute
13
 * 
14
 * @property int $id 主键
15
 * @property int $dynamic_attribute_id 单元ID
16
 * @property string $model_id 关联ID
17
 * @property ?string<class-string> $model_type 关联类
18
 * @property array $extra 自定义参数
19
 * 
20
 * @property-read ?\Carbon\Carbon $created_at 创建时间
21
 * @property-read ?\Carbon\Carbon $updated_at 更新时间
22
 * @property-read ?array<string,string> $thumbnail 附件信息
23
 * @property-read ?DynamicAttribute $dynamicAttribute 单元
24
 * @property-read ?\Illuminate\Database\Eloquent\Collection<Media> $media 附件
25
 * @property-read mixed $model 上级
26
 */
27
class CustomAttribute extends Model implements HasMedia
28
{
29
    use MediaAttributeTrait, HasFactory;
30
    protected $fillable = [
31
        'dynamic_attribute_id',
32
        'model_id',
33
        'model_type',
34
        'extra',
35
    ];
36
37
    public $casts = [
38
        'extra' => 'json',
39
        'thumbnail' => 'json',
40
        'created_at' => 'datetime',
41
        'updated_at' => 'datetime'
42
    ];
43
44
    /**
45
     * 动态单元
46
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
47
     */
48
    public function dynamicAttribute()
49
    {
50
        return $this->belongsTo(DynamicAttribute::class);
51
    }
52
53
    /**
54
     * 关联模型
55
     * @return \Illuminate\Database\Eloquent\Relations\MorphTo
56
     */
57
    public function model()
58
    {
59
        return $this->morphTo();
60
    }
61
}
62