@@ -261,7 +261,10 @@ public function store(Request $request, $parentKey)
261261 $ request ->get ('pivot ' , [])
262262 );
263263
264- $ entity = $ this ->newRelationQuery ($ parentEntity )->with ($ requestedRelations )->find ($ entity ->id );
264+ $ entity = $ this ->newRelationQuery ($ parentEntity )->with ($ requestedRelations )->where (
265+ $ this ->resolveQualifiedKeyName (),
266+ $ entity ->{$ this ->keyName ()}
267+ )->firstOrFail ();
265268 $ entity ->wasRecentlyCreated = true ;
266269
267270 $ entity = $ this ->cleanupEntity ($ entity );
@@ -590,7 +593,10 @@ public function update(Request $request, $parentKey, $relatedKey = null)
590593 $ request ->get ('pivot ' , [])
591594 );
592595
593- $ entity = $ this ->newRelationQuery ($ parentEntity )->with ($ requestedRelations )->find ($ entity ->id );
596+ $ entity = $ this ->newRelationQuery ($ parentEntity )->with ($ requestedRelations )->where (
597+ $ this ->resolveQualifiedKeyName (),
598+ $ entity ->{$ this ->keyName ()}
599+ )->firstOrFail ();
594600
595601 $ entity = $ this ->cleanupEntity ($ entity );
596602
@@ -754,9 +760,10 @@ public function destroy(Request $request, $parentKey, $relatedKey = null)
754760 if (!$ forceDeletes ) {
755761 $ this ->performDestroy ($ entity );
756762 if ($ softDeletes ) {
757- $ entity = $ this ->newRelationQuery ($ parentEntity )->withTrashed ()->with ($ requestedRelations )->find (
758- $ entity ->id
759- );
763+ $ entity = $ this ->newRelationQuery ($ parentEntity )->withTrashed ()->with ($ requestedRelations )->where (
764+ $ this ->resolveQualifiedKeyName (),
765+ $ entity ->{$ this ->keyName ()}
766+ )->firstOrFail ();
760767 }
761768 } else {
762769 $ this ->performForceDestroy ($ entity );
@@ -915,7 +922,10 @@ public function restore(Request $request, $parentKey, $relatedKey = null)
915922
916923 $ this ->performRestore ($ entity );
917924
918- $ entity = $ this ->newRelationQuery ($ parentEntity )->with ($ requestedRelations )->find ($ entity ->id );
925+ $ entity = $ this ->newRelationQuery ($ parentEntity )->with ($ requestedRelations )->where (
926+ $ this ->resolveQualifiedKeyName (),
927+ $ entity ->{$ this ->keyName ()}
928+ )->firstOrFail ();
919929
920930 $ entity = $ this ->cleanupEntity ($ entity );
921931
0 commit comments