12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- <?php
- namespace App\Repositories\Models\Base;
- use App\Repositories\Models\Model;
- use Carbon\Carbon;
- class Banner extends Model
- {
- /**
- * @var string
- */
- protected $table = 'base_banners';
- protected $guarded = [];
- protected $casts = [
- 'body' => 'json'
- ];
- /**
- * The attributes excluded from the model's JSON form.
- *
- * @var array
- */
- protected $hidden = [];
- protected static function booted()
- {
- parent::booted(); // TODO: Change the autogenerated stub
- self::saving(function (Banner $banner) {
- if (empty($banner->start_time)) {
- $banner->start_time = Carbon::now()->toDateTimeString();
- }
- });
- }
- public function getUrlAttribute()
- {
- if (array_key_exists('cover', $this->attributes)) return path_to_url($this->attributes['cover']);
- return '';
- }
- public function scopeActive($query)
- {
- $now = Carbon::now();
- return $query->where('start_time', '<=', $now)->where('end_time', '>=', $now);
- }
- }
|