35 lines
834 B
PHP
35 lines
834 B
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use EloquentFilter\Filterable;
|
|
|
|
class AdminNotice extends Model
|
|
{
|
|
use Filterable;
|
|
|
|
protected $fillable = ['title', 'content', 'article_id', 'remark', 'is_enable', 'published_at' ,'sort'];
|
|
protected $casts = [
|
|
'published_at' => 'datetime:Y-m-d H:i:s',
|
|
'created_at' => 'datetime:Y-m-d H:i:s',
|
|
'updated_at' => 'datetime:Y-m-d H:i:s',
|
|
'is_enable' => 'boolean'
|
|
];
|
|
|
|
public function article()
|
|
{
|
|
return $this->belongsTo(Article::class, 'article_id');
|
|
}
|
|
|
|
public function scopeSort($q)
|
|
{
|
|
return $q->orderBy('sort', 'desc')->orderBy('published_at', 'desc');
|
|
}
|
|
|
|
public function scopeShow($q)
|
|
{
|
|
return $q->where('is_enable', 1)->where('published_at', '<=', now());
|
|
}
|
|
}
|