1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- <?php
- namespace App\Repositories\Models\Base;
- use App\Repositories\Models\Model;
- use App\Repositories\Models\Base\Resource;
- use Carbon\Carbon;
- use Prettus\Repository\Contracts\Transformable;
- use Prettus\Repository\Traits\TransformableTrait;
- /**
- * Class Banner.
- *
- * @package namespace App\Repositories\Models\Base;
- */
- class Banner extends Model implements Transformable
- {
- use TransformableTrait;
- protected $table = 'base_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);
- }
- }
|