DistProduct.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. namespace App\Models;
  3. use Dcat\Admin\Traits\HasDateTimeFormatter;
  4. use App\Traits\SortableTraitPinned;
  5. use Illuminate\Database\Eloquent\Model;
  6. class DistProduct extends Model
  7. {
  8. use HasDateTimeFormatter;
  9. use SortableTraitPinned;
  10. protected $table = 'dist_product';
  11. // 可选:你可以在这里自定义排序配置
  12. public $sortable = [
  13. 'order_column_name' => 'order', // 排序字段
  14. 'sort_when_creating' => true, // 创建时自动排序
  15. ];
  16. protected $casts = [
  17. 'created_at' => 'datetime:Y-m-d H:i:s',
  18. 'updated_at' => 'datetime:Y-m-d H:i:s',
  19. 'parameters' => 'json', // 将 attributes 字段转换为数组
  20. ];
  21. protected $fillable = [
  22. 'id',
  23. 'title',
  24. 'keywords',
  25. 'description',
  26. 'sku',
  27. 'category_id',
  28. 'issuance_date',
  29. 'order',
  30. 'enabled',
  31. 'content',
  32. 'parameters',
  33. 'created_at',
  34. 'updated_at',
  35. 'is_pinned',
  36. 'dist_id',
  37. ];
  38. public function distProductCategory()
  39. {
  40. return $this->hasOne(DistProductCategory::class,'id','category_id');
  41. }
  42. // 一对多关联
  43. public function images()
  44. {
  45. return $this->hasMany(DistProductImage::class, 'product_id');
  46. }
  47. }