DistProduct.php 1.5 KB

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