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

45 lines
918 B

4 years ago
  1. <?php
  2. namespace App\Models;
  3. use Illuminate\Database\Eloquent\Factories\HasFactory;
  4. use Illuminate\Database\Eloquent\SoftDeletes;
  5. /**
  6. * 供应商产品
  7. * Class Product
  8. * @package App\Models
  9. */
  10. class Product extends BaseModel
  11. {
  12. use HasFactory, SoftDeletes;
  13. protected $guarded = ['id']; //不允许编辑的字段
  14. protected $appends = ['picture'];
  15. // 获取所有产品图片
  16. public function getPicturesAttribute($value): array
  17. {
  18. if (is_string($value)) {
  19. $value = $value ? json_decode($value, true) : [];
  20. }
  21. $this->append('picture');
  22. return $value ?? [];
  23. }
  24. // 获取第一张产品图片
  25. public function getPictureAttribute($value): string
  26. {
  27. return $this->pictures[0] ?? '';
  28. }
  29. public function supplier()
  30. {
  31. return $this->belongsTo(Supplier::class);
  32. }
  33. public function category()
  34. {
  35. return $this->belongsTo(Category::class);
  36. }
  37. }