You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
941 B

  1. <?php
  2. namespace App\Model\v3;
  3. use App\Model\Model;
  4. use Hyperf\Database\Model\Builder;
  5. use Hyperf\Database\Model\SoftDeletes;
  6. class Banner extends Model
  7. {
  8. use SoftDeletes;
  9. protected $table = 'lanzu_banners';
  10. protected $appends = [
  11. 'cover_url'
  12. ];
  13. protected $visible = [
  14. 'id', 'cover_type', 'title', 'subtitle', 'path', 'path_type', 'bg_color','cover_url'
  15. ];
  16. public function getCoverUrlAttribute(){
  17. return $this->imageUrl($this->cover);
  18. }
  19. public function imageUrl($value)
  20. {
  21. if(strripos($value,"http") === false){
  22. return env('OSS_IMG_HOST').'/'.$value;
  23. }else{
  24. return $value;
  25. }
  26. }
  27. protected function boot(): void
  28. {
  29. parent::boot();
  30. self::addGlobalScope('normal', function (Builder $builder) {
  31. return $builder->where(['status' => 1])->orderBy('sort', 'desc');
  32. });
  33. }
  34. }