Banner.php 838 B

123456789101112131415161718192021222324252627282930313233
  1. <?php
  2. namespace App\Models;
  3. use App\Constants\Util;
  4. class Banner extends BaseModel
  5. {
  6. public const TYPE_BOTH = 'both';
  7. protected $table = 'banner';
  8. protected $fillable = ['title', 'image', 'link' ,'type' ,'sort' ,'cny_rate','lang', 'status', 'click_type', 'link_pc', 'link_h5'];
  9. protected $casts = ['status' => 'integer'];
  10. protected $appends = ['types'];
  11. protected function getTypesAttribute(): array
  12. {
  13. return match ($this->type) {
  14. self::TYPE_BOTH => ['app', 'pc'],
  15. 'app', 'pc' => [$this->type],
  16. default => [],
  17. };
  18. }
  19. protected function getImageAttribute($value)
  20. {
  21. return Util::ensureUrl($value);
  22. }
  23. protected function setImageAttribute($value)
  24. {
  25. $this->attributes['image'] = Util::replacePartInUrl($value);
  26. }
  27. }