@@ -174,6 +174,11 @@ protected function storeWithTransaction(Request $request)
174174 $ request ->all ()
175175 );
176176
177+ $ beforeStoreFreshResult = $ this ->beforeStoreFresh ($ request , $ entity );
178+ if ($ this ->hookResponds ($ beforeStoreFreshResult )) {
179+ return $ beforeStoreFreshResult ;
180+ }
181+
177182 $ entity = $ entity ->fresh ($ requestedRelations );
178183 $ entity ->wasRecentlyCreated = true ;
179184
@@ -229,6 +234,18 @@ protected function performStore(Request $request, Model $entity, array $attribut
229234 $ entity ->save ();
230235 }
231236
237+ /**
238+ * The hook is executed after creating and before refreshing the resource.
239+ *
240+ * @param Request $request
241+ * @param Model $entity
242+ * @return mixed
243+ */
244+ protected function beforeStoreFresh (Request $ request , Model $ entity )
245+ {
246+ return null ;
247+ }
248+
232249 /**
233250 * The hook is executed after creating or updating a resource.
234251 *
@@ -398,6 +415,11 @@ protected function updateWithTransaction(Request $request, $key)
398415 $ request ->all ()
399416 );
400417
418+ $ beforeUpdateFreshResult = $ this ->beforeUpdateFresh ($ request , $ entity );
419+ if ($ this ->hookResponds ($ beforeUpdateFreshResult )) {
420+ return $ beforeUpdateFreshResult ;
421+ }
422+
401423 $ entity = $ entity ->fresh ($ requestedRelations );
402424
403425 $ afterSaveHookResult = $ this ->afterSave ($ request , $ entity );
@@ -465,6 +487,18 @@ protected function performUpdate(Request $request, Model $entity, array $attribu
465487 $ entity ->save ();
466488 }
467489
490+ /**
491+ * The hook is executed after updating and before refreshing the resource.
492+ *
493+ * @param Request $request
494+ * @param Model $entity
495+ * @return mixed
496+ */
497+ protected function beforeUpdateFresh (Request $ request , Model $ entity )
498+ {
499+ return null ;
500+ }
501+
468502 /**
469503 * The hook is executed after updating a resource.
470504 *
@@ -529,6 +563,11 @@ protected function destroyWithTransaction(Request $request, $key)
529563 if (!$ forceDeletes ) {
530564 $ this ->performDestroy ($ entity );
531565 if ($ softDeletes ) {
566+ $ beforeDestroyFreshResult = $ this ->beforeDestroyFresh ($ request , $ entity );
567+ if ($ this ->hookResponds ($ beforeDestroyFreshResult )) {
568+ return $ beforeDestroyFreshResult ;
569+ }
570+
532571 $ entity = $ entity ->fresh ($ requestedRelations );
533572 }
534573 } else {
@@ -610,6 +649,19 @@ protected function performForceDestroy(Model $entity): void
610649 $ entity ->forceDelete ();
611650 }
612651
652+ /**
653+ * The hook is executed after deleting and before refreshing the resource.
654+ * This hook is only called when not using forced deletes
655+ *
656+ * @param Request $request
657+ * @param Model $entity
658+ * @return mixed
659+ */
660+ protected function beforeDestroyFresh (Request $ request , Model $ entity )
661+ {
662+ return null ;
663+ }
664+
613665 /**
614666 * The hook is executed after deleting a resource.
615667 *
@@ -666,6 +718,11 @@ protected function restoreWithTransaction(Request $request, $key)
666718
667719 $ this ->performRestore ($ entity );
668720
721+ $ beforeHookResult = $ this ->beforeRestoreFresh ($ request , $ entity );
722+ if ($ this ->hookResponds ($ beforeHookResult )) {
723+ return $ beforeHookResult ;
724+ }
725+
669726 $ entity = $ entity ->fresh ($ requestedRelations );
670727
671728 $ afterHookResult = $ this ->afterRestore ($ request , $ entity );
@@ -726,6 +783,19 @@ protected function performRestore(Model $entity): void
726783 $ entity ->restore ();
727784 }
728785
786+ /**
787+ * The hook is executed after force restoring a previously deleted resource but before
788+ * refreshing the resource.
789+ *
790+ * @param Request $request
791+ * @param Model $entity
792+ * @return mixed
793+ */
794+ protected function beforeRestoreFresh (Request $ request , Model $ entity )
795+ {
796+ return null ;
797+ }
798+
729799 /**
730800 * The hook is executed after force restoring a previously deleted resource.
731801 *
0 commit comments