@@ -174,6 +174,11 @@ protected function storeWithTransaction(Request $request)
174
174
$ request ->all ()
175
175
);
176
176
177
+ $ beforeStoreFreshResult = $ this ->beforeStoreFresh ($ request , $ entity );
178
+ if ($ this ->hookResponds ($ beforeStoreFreshResult )) {
179
+ return $ beforeStoreFreshResult ;
180
+ }
181
+
177
182
$ entity = $ entity ->fresh ($ requestedRelations );
178
183
$ entity ->wasRecentlyCreated = true ;
179
184
@@ -229,6 +234,18 @@ protected function performStore(Request $request, Model $entity, array $attribut
229
234
$ entity ->save ();
230
235
}
231
236
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
+
232
249
/**
233
250
* The hook is executed after creating or updating a resource.
234
251
*
@@ -398,6 +415,11 @@ protected function updateWithTransaction(Request $request, $key)
398
415
$ request ->all ()
399
416
);
400
417
418
+ $ beforeUpdateFreshResult = $ this ->beforeUpdateFresh ($ request , $ entity );
419
+ if ($ this ->hookResponds ($ beforeUpdateFreshResult )) {
420
+ return $ beforeUpdateFreshResult ;
421
+ }
422
+
401
423
$ entity = $ entity ->fresh ($ requestedRelations );
402
424
403
425
$ afterSaveHookResult = $ this ->afterSave ($ request , $ entity );
@@ -465,6 +487,18 @@ protected function performUpdate(Request $request, Model $entity, array $attribu
465
487
$ entity ->save ();
466
488
}
467
489
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
+
468
502
/**
469
503
* The hook is executed after updating a resource.
470
504
*
@@ -529,6 +563,11 @@ protected function destroyWithTransaction(Request $request, $key)
529
563
if (!$ forceDeletes ) {
530
564
$ this ->performDestroy ($ entity );
531
565
if ($ softDeletes ) {
566
+ $ beforeDestroyFreshResult = $ this ->beforeDestroyFresh ($ request , $ entity );
567
+ if ($ this ->hookResponds ($ beforeDestroyFreshResult )) {
568
+ return $ beforeDestroyFreshResult ;
569
+ }
570
+
532
571
$ entity = $ entity ->fresh ($ requestedRelations );
533
572
}
534
573
} else {
@@ -610,6 +649,19 @@ protected function performForceDestroy(Model $entity): void
610
649
$ entity ->forceDelete ();
611
650
}
612
651
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
+
613
665
/**
614
666
* The hook is executed after deleting a resource.
615
667
*
@@ -666,6 +718,11 @@ protected function restoreWithTransaction(Request $request, $key)
666
718
667
719
$ this ->performRestore ($ entity );
668
720
721
+ $ beforeHookResult = $ this ->beforeRestoreFresh ($ request , $ entity );
722
+ if ($ this ->hookResponds ($ beforeHookResult )) {
723
+ return $ beforeHookResult ;
724
+ }
725
+
669
726
$ entity = $ entity ->fresh ($ requestedRelations );
670
727
671
728
$ afterHookResult = $ this ->afterRestore ($ request , $ entity );
@@ -726,6 +783,19 @@ protected function performRestore(Model $entity): void
726
783
$ entity ->restore ();
727
784
}
728
785
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
+
729
799
/**
730
800
* The hook is executed after force restoring a previously deleted resource.
731
801
*
0 commit comments