diff --git a/app/Activity/Api/SubactivityStoreAction.php b/app/Activity/Api/SubactivityStoreAction.php index e6b6dc81..5a275931 100644 --- a/app/Activity/Api/SubactivityStoreAction.php +++ b/app/Activity/Api/SubactivityStoreAction.php @@ -3,6 +3,7 @@ namespace App\Activity\Api; use App\Subactivity; +use DB; use Illuminate\Http\JsonResponse; use Illuminate\Support\Arr; use Lorisleiva\Actions\ActionRequest; @@ -17,10 +18,12 @@ class SubactivityStoreAction */ public function handle(array $payload): Subactivity { - $subactivity = Subactivity::create(Arr::except($payload, 'activities')); - $subactivity->activities()->sync($payload['activities']); + return DB::transaction(function () use ($payload) { + $subactivity = Subactivity::create(Arr::except($payload, 'activities')); + $subactivity->activities()->sync($payload['activities']); - return $subactivity; + return $subactivity; + }); } /** diff --git a/app/Activity/Api/SubactivityUpdateAction.php b/app/Activity/Api/SubactivityUpdateAction.php index 82f8ebba..33861a45 100644 --- a/app/Activity/Api/SubactivityUpdateAction.php +++ b/app/Activity/Api/SubactivityUpdateAction.php @@ -5,6 +5,7 @@ namespace App\Activity\Api; use App\Activity; use App\Member\Membership; use App\Subactivity; +use DB; use Illuminate\Http\JsonResponse; use Illuminate\Support\Arr; use Illuminate\Validation\Rule; @@ -21,17 +22,19 @@ class SubactivityUpdateAction */ public function handle(Subactivity $subactivity, array $payload): Subactivity { - $subactivity->update(Arr::except($payload, 'activities')); + return DB::transaction(function () use ($subactivity, $payload) { + $subactivity->update(Arr::except($payload, 'activities')); - if (null !== data_get($payload, 'activities')) { - $subactivity->activities()->sync($payload['activities']); - } + if (null !== data_get($payload, 'activities')) { + $subactivity->activities()->sync($payload['activities']); + } - return $subactivity; + return $subactivity; + }); } /** - * @return array + * @return array> */ public function rules(): array {