@@ -326,6 +326,15 @@ public function createRecordFromRequest($request, ?callable $onBefore = null, ?c
326326 return $ record ;
327327 }
328328
329+ if (is_callable ($ onAfter )) {
330+ $ after = $ onAfter ($ request , $ record , $ input );
331+ if ($ after instanceof JsonResponse) {
332+ return $ after ;
333+ }
334+ }
335+
336+ $ record ->refresh ();
337+
329338 // PERFORMANCE OPTIMIZATION: Use load() instead of re-querying the database
330339 // This avoids an unnecessary second database query
331340 $ with = $ request ->or (['with ' , 'expand ' ], []);
@@ -339,13 +348,6 @@ public function createRecordFromRequest($request, ?callable $onBefore = null, ?c
339348 $ record ->loadCount ($ withCount );
340349 }
341350
342- if (is_callable ($ onAfter )) {
343- $ after = $ onAfter ($ request , $ record , $ input );
344- if ($ after instanceof JsonResponse) {
345- return $ after ;
346- }
347- }
348-
349351 return static ::mutateModelWithRequest ($ request , $ record );
350352 }
351353
@@ -418,6 +420,15 @@ public function updateRecordFromRequest(Request $request, $id, ?callable $onBefo
418420 return $ record ;
419421 }
420422
423+ if (is_callable ($ onAfter )) {
424+ $ after = $ onAfter ($ request , $ record , $ input );
425+ if ($ after instanceof JsonResponse) {
426+ return $ after ;
427+ }
428+ }
429+
430+ $ record ->refresh ();
431+
421432 // PERFORMANCE OPTIMIZATION: Use load() instead of re-querying the database
422433 // This avoids an unnecessary second database query
423434 $ with = $ request ->or (['with ' , 'expand ' ], []);
@@ -431,13 +442,6 @@ public function updateRecordFromRequest(Request $request, $id, ?callable $onBefo
431442 $ record ->loadCount ($ withCount );
432443 }
433444
434- if (is_callable ($ onAfter )) {
435- $ after = $ onAfter ($ request , $ record , $ input );
436- if ($ after instanceof JsonResponse) {
437- return $ after ;
438- }
439- }
440-
441445 return static ::mutateModelWithRequest ($ request , $ record );
442446 }
443447
0 commit comments