syncSpices(); } protected function syncSpices(): void { $recipe = $this->record; $spices = collect($this->data['spices'] ?? []) ->mapWithKeys(function ($spice) { return [ $spice['spice_id'] => ['amount_in_percent' => $spice['amount_in_percent']], ]; }) ->toArray(); $recipe->spices()->sync($spices); } }