'integer', 'brand' => 'integer', 'year' => 'integer', 'module' => 'integer', 'deleted_at' => 'integer', 'created_at' => 'datetime', 'updated_at' => 'datetime', 'created_by' => 'integer', 'updated_by' => 'integer', 'spider_article_id' => 'integer', 'style' => 'integer', 'location' => 'integer', 'images_count' => 'integer', 'published_status' => 'integer', 'published_at' => 'integer']; protected ?string $dateFormat = 'U'; // public function saving(Saving $event) // { // if ($this->getAttribute('images_count') == 0) { // $this->setAttribute('images_count', count(json_decode($this->getAttribute('images'), true))); // } // } public function setImagesAttribute($value) { if (is_string($value)) { $imagesValue = json_decode($value, true); $this->setAttribute('images_count', count($imagesValue)); } elseif (is_array($value)) { $this->setAttribute('images_count', count($value)); $value = json_encode(array_values($value)); } $this->attributes['images'] = $value; } public function getImagesAttribute($value) { return $this->format('images', function (bool $isFormat) use ($value) { return $isFormat ? json_decode($value, true) : $value; }); } public function getModuleAttribute($value) { return $this->format('module', function (bool $isFormat) use ($value) { return $isFormat ? ArticleModuleEnum::from($value)->toString() : $value; }); } public function getLocationAttribute($value) { return $this->format('location', function (bool $isFormat) use ($value) { return $isFormat ? LocationEnum::from($value)->toString() : $value; }); } public function getBrandAttribute($value) { return $this->format('brand', function (bool $isFormat) use ($value) { return $isFormat ? AppBrand::find($value)?->name : $value; }); } public function getBrandNameAttribute($value) { return $this->format('brand_name', function (bool $isFormat) use ($value) { return $isFormat ? AppBrand::find($value)?->name : $value; }); } public function getPublishedStatusAttribute($value) { return $this->format('published_status', function (bool $isFormat) use ($value) { return $isFormat ? ArticlePublishedStatusEnum::from($value)->toString() : $value; }); } public function getTranslateTitleAttribute($value) { return $this->format('translate_title', function (bool $isFormat) use ($value) { return $isFormat ? TitleHelper::translate($value) : $value; }); } }