1 | <?php |
||
13 | abstract class Value extends Model |
||
14 | { |
||
15 | use ValidatingTrait; |
||
16 | |||
17 | /** |
||
18 | * {@inheritdoc} |
||
19 | */ |
||
20 | protected $fillable = [ |
||
21 | 'content', |
||
22 | 'attribute_id', |
||
23 | 'entity_id', |
||
24 | 'entity_type', |
||
25 | ]; |
||
26 | |||
27 | /** |
||
28 | * Determine if value should push to relations when saving. |
||
29 | * |
||
30 | * @var bool |
||
31 | */ |
||
32 | protected $shouldPush = false; |
||
33 | |||
34 | /** |
||
35 | * The default rules that the model will validate against. |
||
36 | * |
||
37 | * @var array |
||
38 | */ |
||
39 | protected $rules = []; |
||
40 | |||
41 | /** |
||
42 | * Whether the model should throw a |
||
43 | * ValidationException if it fails validation. |
||
44 | * |
||
45 | * @var bool |
||
46 | */ |
||
47 | protected $throwValidationExceptions = true; |
||
48 | |||
49 | /** |
||
50 | * Relationship to the attribute entity. |
||
51 | * |
||
52 | * @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
||
53 | */ |
||
54 | public function attribute(): BelongsTo |
||
55 | { |
||
56 | return $this->belongsTo(Attribute::class, 'attribute_id', 'id', 'attribute'); |
||
57 | } |
||
58 | |||
59 | /** |
||
60 | * Polymorphic relationship to the entity instance. |
||
61 | * |
||
62 | * @return \Illuminate\Database\Eloquent\Relations\MorphTo |
||
63 | */ |
||
64 | public function entity(): MorphTo |
||
65 | { |
||
66 | return $this->morphTo('entity', 'entity_type', 'entity_id', 'id'); |
||
67 | } |
||
68 | |||
69 | /** |
||
70 | * Check if value should push to relations when saving. |
||
71 | * |
||
72 | * @return bool |
||
73 | */ |
||
74 | public function shouldPush(): bool |
||
78 | |||
79 | /** |
||
80 | * {@inheritdoc} |
||
81 | */ |
||
82 | public function newCollection(array $models = []) |
||
86 | } |
||
87 |