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

27 lines
637 B

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