123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- <?php
- namespace App\Repositories\Models\CMS;
- use App\Repositories\Models\Base\Resource;
- use App\Repositories\Models\Model;
- use Carbon\Carbon;
- use Prettus\Repository\Contracts\Transformable;
- use Prettus\Repository\Traits\TransformableTrait;
- /**
- * Class Banner.
- *
- * @package namespace App\Repositories\Models\CMS;
- */
- class Banner extends Model implements Transformable
- {
- use TransformableTrait;
- /**
- * The attributes that are mass assignable.
- *
- * @var array
- */
- protected $table = 'cms_banners';
- /**
- * The attributes that are mass assignable.
- *
- * @var array
- */
- protected $guarded = [];
- protected $casts = ['click_body' => 'array'];
- protected static function booted()
- {
- self::language();
- static::saving(function (Banner $banner) {
- if (empty($banner->start_time)) {
- $banner->start_time = Carbon::now()->toDateTimeString();
- }
- });
- }
- public function cover_resource()
- {
- return $this->belongsTo(Resource::class, 'cover', 'id')->select(['id', 'url', 'path']);
- }
- public function scopeActive($query)
- {
- $now = Carbon::now();
- return $query->where('start_time', '<=', $now)->where('end_time', '>=', $now);
- }
- }
|