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

44 lines
883 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. // 获取所有产品图片
  15. public function getPicturesAttribute($value): array
  16. {
  17. if (is_string($value)) {
  18. $value = $value ? json_decode($value, true) : [];
  19. }
  20. $this->append('picture');
  21. return $value ?? [];
  22. }
  23. // 获取第一张产品图片
  24. public function getPictureAttribute($value): string
  25. {
  26. return $this->pictures[0] ?? '';
  27. }
  28. public function supplier()
  29. {
  30. return $this->belongsTo(Supplier::class);
  31. }
  32. public function category()
  33. {
  34. return $this->belongsTo(Category::class);
  35. }
  36. }