generated from panliang/owl-admin-starter
54 lines
1.2 KiB
PHP
54 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use EloquentFilter\Filterable;
|
|
use App\Traits\HasDateTimeFormatter;
|
|
use App\Casts\StorageFile;
|
|
|
|
/**
|
|
* 文章
|
|
*/
|
|
class Article extends Model
|
|
{
|
|
use Filterable, HasDateTimeFormatter;
|
|
|
|
protected $fillable = [
|
|
'category_id', 'category_path', 'key',
|
|
'title', 'cover', 'description', 'author', 'content',
|
|
'files', 'medias', 'extension',
|
|
'is_enable', 'is_recommend',
|
|
'published_at', 'remarks', 'sort',
|
|
'party_cate_id',
|
|
];
|
|
|
|
protected $casts = [
|
|
'cover' => StorageFile::class,
|
|
'files' => 'array',
|
|
'medias' => 'array',
|
|
'extension' => 'array',
|
|
'published_at' => 'datetime',
|
|
];
|
|
|
|
public static function getCategoryList()
|
|
{
|
|
return Keyword::where('key', 'like', 'category_%')->get();
|
|
}
|
|
|
|
public function category()
|
|
{
|
|
return $this->belongsTo(Keyword::class, 'category_id');
|
|
}
|
|
|
|
public function scopeSort($q)
|
|
{
|
|
return $q->orderBy('sort', 'asc')->latest('published_at')->latest('id');
|
|
}
|
|
|
|
public function scopePublish($q)
|
|
{
|
|
return $q->where('published_at', '<=', now())->where('is_enable', 1);
|
|
}
|
|
}
|