Files
2026-08-08 18:27:38 +08:00

57 lines
1.2 KiB
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class News extends Model
{
use SoftDeletes;
protected $fillable = [
'title',
'slug',
'category',
'summary',
'body',
'cover',
'status',
'published_at',
'seo_title',
'seo_description',
];
protected $casts = [
'published_at' => 'datetime',
];
public const CATEGORIES = [
'industry' => '行业资讯',
'company' => '公司动态',
'event' => '展会活动',
];
public function scopePublished($query)
{
return $query->where('status', 'published')
->whereNotNull('published_at')
->orderByDesc('published_at');
}
public function categoryLabel(): string
{
return self::CATEGORIES[$this->category] ?? $this->category ?? '—';
}
public function seoTitle(): string
{
return $this->seo_title ?: $this->title;
}
public function seoDescription(): string
{
return $this->seo_description ?: ($this->summary ?: $this->title);
}
}