'Draft', 12 => 'Scheduled', 13 => 'Published', 14 => 'Archived', ]; /** * The attributes that are mass assignable. */ protected $fillable = [ 'title', 'product_id', 'category_id', 'release_date', 'release_time', 'creative', 'caption', 'desc', 'order', 'createdby', 'updatedby', 'status', 'remarks', ]; protected $appends = ['status_name']; protected $casts = [ 'release_date' => 'date:Y-m-d', 'release_time' => 'datetime:H:i:s', ]; protected function statusName(): Attribute { return Attribute::make( get: function (mixed $value, array $attributes) { switch ($attributes['status']) { case '11': return '' . self::STATUS[$attributes['status']] . ''; case '12': return '' . self::STATUS[$attributes['status']] . ''; case '13': return '' . self::STATUS[$attributes['status']] . ''; case '14': return '' . self::STATUS[$attributes['status']] . ''; default: # code... break; } }, set: fn($value) => $value, ); } public function product() { return $this->belongsTo(Product::class, 'product_id'); } public function category() { return $this->belongsTo(ContentCategory::class, 'category_id'); } public function activityLogs(): MorphMany { return $this->morphMany(ActivityLog::class, 'loggable')->latest(); } public function createLog($data) { return $this->activityLogs()->create($data); } }