海南旅游SAAS
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.

31 lines
704 B

  1. <?php
  2. namespace App\Models;
  3. use Illuminate\Database\Eloquent\Factories\HasFactory;
  4. use Illuminate\Database\Eloquent\SoftDeletes;
  5. class Product extends BaseModel
  6. {
  7. use HasFactory, SoftDeletes;
  8. protected $dateFormat = 'U';
  9. // 获取所有产品图片
  10. public function getPicturesAttribute($value): array
  11. {
  12. $pictures = $value ? json_decode($value, true) : [];
  13. $this->append('picture');
  14. return $pictures;
  15. }
  16. // 获取第一张产品图片
  17. public function getPictureAttribute($value): string
  18. {
  19. return $this->pictures[0] ?? '';
  20. }
  21. public function productInfo()
  22. {
  23. return $this->hasOne('App\Models\ProductInfo');
  24. }
  25. }