*/ protected $fillable = [ 'type', 'content_html', 'content_summary', 'author_name', 'author_title', 'company_name', 'company_logo_path', 'image_path', 'text_position', 'sort', 'status', 'featured', 'published_at', ]; /** * The attributes that should be cast. * * @var array */ protected $casts = [ 'sort' => 'integer', 'featured' => 'boolean', 'published_at' => 'datetime', 'created_at' => 'datetime', 'updated_at' => 'datetime', ]; /** * Default values for attributes. * * @var array */ protected $attributes = [ 'sort' => 999, 'status' => 'draft', 'featured' => false, 'text_position' => 'left', ]; /** * Scope a query to only include voices of a given type. */ public function scopeOfType(Builder $query, string $type): Builder { return $query->where('type', $type); } /** * Scope a query to only include published voices. * * Note: 專案既有慣例使用 status='publish' * published_at 若有值,視為可排程發布。 */ public function scopePublished(Builder $query): Builder { return $query->where('status', 'publish') ->where(function (Builder $q) { $q->whereNull('published_at') ->orWhere('published_at', '<=', now()); }); } /** * Scope a query to order voices by sort field (ascending). */ public function scopeOrdered(Builder $query): Builder { return $query->orderBy('sort', 'asc')->orderBy('id', 'desc'); } }