'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 字段转换为数组 ]; protected $fillable = [ 'id', 'title', 'keywords', 'description', 'sku', 'category_id', 'issuance_date', 'order', 'enabled', 'content', 'parameters', 'created_at', 'updated_at', 'is_pinned', 'dist_id', 'seo_title', 'seo_keywords', 'seo_description', 'slug', 'status', 'review_reply', 'album_id', ]; public function distProductCategory() { return $this->hasOne(DistProductCategory::class,'id','category_id'); } // 一对多关联 public function images() { return $this->hasMany(DistProductImage::class, 'product_id')->orderBy('order', 'asc')->orderBy('id', 'asc'); } }