初始化
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
<?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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user