@@ -295,22 +295,22 @@ private function createManyEntries($entry, $relation, $relationMethod, $relation
295295 {
296296 $ items = $ relationDetails ['values ' ][$ relationMethod ];
297297
298- $ relation_local_key = $ relation ->getLocalKeyName ();
298+ $ relatedModelLocalKey = $ relation ->getRelated ()-> getKeyName ();
299299
300300 $ relatedItemsSent = [];
301301
302302 foreach ($ items as $ item ) {
303303 [$ directInputs , $ relationInputs ] = $ this ->splitInputIntoDirectAndRelations ($ item , $ relationDetails , $ relationMethod );
304304 // for each item we get the inputs to create and the relations of it.
305- $ relation_local_key_value = $ item [$ relation_local_key ] ?? null ;
305+ $ relatedModelLocalKeyValue = $ item [$ relatedModelLocalKey ] ?? null ;
306306
307307 // we either find the matched entry by local_key (usually `id`)
308308 // and update the values from the input
309309 // or create a new item from input
310- $ item = $ entry ->{$ relationMethod }()->updateOrCreate ([$ relation_local_key => $ relation_local_key_value ], $ directInputs );
310+ $ item = $ entry ->{$ relationMethod }()->updateOrCreate ([$ relatedModelLocalKey => $ relatedModelLocalKeyValue ], $ directInputs );
311311
312312 // we store the item local key so we can match them with database and check if any item was deleted
313- $ relatedItemsSent [] = $ item ->{$ relation_local_key };
313+ $ relatedItemsSent [] = $ item ->{$ relatedModelLocalKey };
314314
315315 // create the item relations if any.
316316 $ this ->createRelationsForItem ($ item , $ relationInputs );
@@ -319,7 +319,7 @@ private function createManyEntries($entry, $relation, $relationMethod, $relation
319319 // use the collection of sent ids to match agains database ids, delete the ones not found in the submitted ids.
320320 if (! empty ($ relatedItemsSent )) {
321321 // we perform the cleanup of removed database items
322- $ entry ->{$ relationMethod }()->whereNotIn ($ relation_local_key , $ relatedItemsSent )->delete ();
322+ $ entry ->{$ relationMethod }()->whereNotIn ($ relatedModelLocalKey , $ relatedItemsSent )->delete ();
323323 }
324324 }
325325}
0 commit comments