'order', // 排序字段 'sort_when_creating' => true, // 创建时自动排序 ]; protected $casts = [ 'created_at' => 'datetime:Y-m-d H:i:s', 'updated_at' => 'datetime:Y-m-d H:i:s', 'parameters' => 'json', // 将 attributes 字段转换为数组 ]; public function baseProductCategory() { return $this->hasOne(BaseProductCategory::class,'id','category_id'); } protected $fillable = [ 'id', 'title', 'keywords', 'description', 'sku', 'category_id', 'issuance_date', 'order', 'enabled', 'content', 'parameters', 'created_at', 'updated_at', 'is_pinned', ]; // 一对多关联 public function images() { return $this->hasMany(BaseProductImage::class, 'product_id','id')->orderBy('order', 'asc')->orderBy('id', 'asc'); } }