DistProduct.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. 'seo_title',
  38. 'seo_keywords',
  39. 'seo_description',
  40. 'slug',
  41. ];
  42. public function distProductCategory()
  43. {
  44. return $this->hasOne(DistProductCategory::class,'id','category_id');
  45. }
  46. // 一对多关联
  47. public function images()
  48. {
  49. return $this->hasMany(DistProductImage::class, 'product_id');
  50. }
  51. }