DistProduct.php 963 B

1234567891011121314151617181920212223242526272829303132333435363738
  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. public function distProductCategory()
  22. {
  23. return $this->hasOne(DistProductCategory::class,'id','category_id');
  24. }
  25. // 一对多关联
  26. public function images()
  27. {
  28. return $this->hasMany(DistProductImage::class, 'product_id');
  29. }
  30. }