generated from panliang/owl-admin-starter
44 lines
941 B
PHP
44 lines
941 B
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use EloquentFilter\Filterable;
|
|
use App\Traits\HasDateTimeFormatter;
|
|
use App\Casts\StorageFile;
|
|
|
|
/**
|
|
* 广告
|
|
*/
|
|
class Banner extends Model
|
|
{
|
|
use Filterable, HasDateTimeFormatter;
|
|
|
|
protected $fillable = ['title', 'picture', 'description', 'place_id', 'path', 'published_at', 'is_enable', 'sort', 'link_config'];
|
|
|
|
protected $casts = [
|
|
'picture' => StorageFile::class,
|
|
'link_config' => 'array',
|
|
];
|
|
|
|
public static function getPlaceList()
|
|
{
|
|
return Keyword::where('key', 'like', 'banner_%')->get();
|
|
}
|
|
|
|
public function place()
|
|
{
|
|
return $this->belongsTo(Keyword::class, 'place_id');
|
|
}
|
|
|
|
public function scopeSort($q)
|
|
{
|
|
return $q->orderBy('sort', 'desc');
|
|
}
|
|
|
|
public function scopeEnable($q)
|
|
{
|
|
return $q->where('is_enable', 1)->where('published_at', '<=', now());
|
|
}
|
|
}
|