1 | <?php |
||
50 | class Attribute extends Model implements Sortable |
||
51 | { |
||
52 | use HasSlug; |
||
53 | use SortableTrait; |
||
54 | use HasTranslations; |
||
55 | use ValidatingTrait; |
||
56 | |||
57 | /** |
||
58 | * {@inheritdoc} |
||
59 | */ |
||
60 | protected $fillable = [ |
||
61 | 'name', |
||
62 | 'slug', |
||
63 | 'description', |
||
64 | 'sort_order', |
||
65 | 'group', |
||
66 | 'type', |
||
67 | 'is_required', |
||
68 | 'is_collection', |
||
69 | 'default', |
||
70 | 'entities', |
||
71 | ]; |
||
72 | |||
73 | /** |
||
74 | * {@inheritdoc} |
||
75 | */ |
||
76 | protected $casts = [ |
||
77 | 'slug' => 'string', |
||
78 | 'sort_order' => 'integer', |
||
79 | 'group' => 'string', |
||
80 | 'type' => 'string', |
||
81 | 'is_required' => 'boolean', |
||
82 | 'is_collection' => 'boolean', |
||
83 | 'default' => 'string', |
||
84 | ]; |
||
85 | |||
86 | /** |
||
87 | * {@inheritdoc} |
||
88 | */ |
||
89 | protected $observables = [ |
||
90 | 'validating', |
||
91 | 'validated', |
||
92 | ]; |
||
93 | |||
94 | /** |
||
95 | * {@inheritdoc} |
||
96 | */ |
||
97 | public $translatable = [ |
||
98 | 'name', |
||
99 | 'description', |
||
100 | ]; |
||
101 | |||
102 | /** |
||
103 | * {@inheritdoc} |
||
104 | */ |
||
105 | public $sortable = [ |
||
106 | 'order_column_name' => 'sort_order', |
||
107 | ]; |
||
108 | |||
109 | /** |
||
110 | * The default rules that the model will validate against. |
||
111 | * |
||
112 | * @var array |
||
113 | */ |
||
114 | protected $rules = []; |
||
115 | |||
116 | /** |
||
117 | * Whether the model should throw a |
||
118 | * ValidationException if it fails validation. |
||
119 | * |
||
120 | * @var bool |
||
121 | */ |
||
122 | protected $throwValidationExceptions = true; |
||
123 | |||
124 | /** |
||
125 | * An array to map class names to their type names in database. |
||
126 | * |
||
127 | * @var array |
||
128 | */ |
||
129 | protected static $typeMap = []; |
||
130 | |||
131 | /** |
||
132 | * Create a new Eloquent model instance. |
||
133 | * |
||
134 | * @param array $attributes |
||
135 | */ |
||
136 | public function __construct(array $attributes = []) |
||
153 | |||
154 | /** |
||
155 | * Enforce clean slugs. |
||
156 | * |
||
157 | * @param string $value |
||
158 | * |
||
159 | * @return void |
||
160 | */ |
||
161 | public function setSlugAttribute($value): void |
||
165 | |||
166 | /** |
||
167 | * Set or get the type map for attribute types. |
||
168 | * |
||
169 | * @param array|null $map |
||
170 | * @param bool $merge |
||
171 | * |
||
172 | * @return array |
||
173 | */ |
||
174 | public static function typeMap(array $map = null, $merge = true) |
||
183 | |||
184 | /** |
||
185 | * Get the model associated with a custom attribute type. |
||
186 | * |
||
187 | * @param string $alias |
||
188 | * |
||
189 | * @return string|null |
||
190 | */ |
||
191 | public static function getTypeModel($alias) |
||
195 | |||
196 | /** |
||
197 | * Access entities relation and retrieve entity types as an array, |
||
198 | * Accessors/Mutators preceeds relation value when called dynamically. |
||
199 | * |
||
200 | * @return array |
||
201 | */ |
||
202 | public function getEntitiesAttribute(): array |
||
206 | |||
207 | /** |
||
208 | * Set the attribute attached entities. |
||
209 | * |
||
210 | * @param \Illuminate\Support\Collection|array $value |
||
211 | * @param mixed $entities |
||
212 | * |
||
213 | * @return void |
||
214 | */ |
||
215 | public function setEntitiesAttribute($entities): void |
||
224 | |||
225 | /** |
||
226 | * Get the options for generating the slug. |
||
227 | * |
||
228 | * @return \Spatie\Sluggable\SlugOptions |
||
229 | */ |
||
230 | public function getSlugOptions(): SlugOptions |
||
238 | |||
239 | /** |
||
240 | * Get the entities attached to this attribute. |
||
241 | * |
||
242 | * @return \Illuminate\Database\Eloquent\Relations\HasMany |
||
243 | */ |
||
244 | public function entities(): HasMany |
||
248 | |||
249 | /** |
||
250 | * Get the entities attached to this attribute. |
||
251 | * |
||
252 | * @param string $value |
||
253 | * |
||
254 | * @return \Illuminate\Database\Eloquent\Relations\HasMany |
||
255 | */ |
||
256 | public function values(string $value): HasMany |
||
260 | } |
||
261 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)
or! empty(...)
instead.