belongsTo(Option::class)->withTrashed(); } public function values() { return $this->belongsToMany(OptionValue::class, 'order_product_option_values') ->using(OrderProductOptionValue::class) ->withPivot('price'); } public function getNameAttribute() { return $this->option->name; } public function isFieldType() { return $this->option->isFieldType(); } public function storeValues($product, $values) { $values = $values->mapWithKeys(function (OptionValue $value) use ($product) { return [$value->id => [ 'price' => $value->priceForProduct($product)->amount(), ]]; }); $this->values()->attach($values->all()); } }