validated(); $labelIds = $validated['action_label_ids'] ?? []; unset($validated['action_label_ids']); $rule = auth()->user()->automationRules()->create($validated); if (! empty($labelIds)) { $rule->labels()->sync($labelIds); $rule->touch(); } return back()->with([ 'saved_automation_rule_id' => $rule->id, 'saved_automation_rule_token' => (string) Str::uuid(), ]); } /** * Update the specified automation rule. */ public function update(UpdateAutomationRuleRequest $request, AutomationRule $automationRule): RedirectResponse { $this->authorize('update', $automationRule); $validated = $request->validated(); $labelIds = $validated['action_label_ids'] ?? []; unset($validated['action_label_ids']); $automationRule->update($validated); $automationRule->labels()->sync($labelIds); $automationRule->touch(); return back()->with([ 'saved_automation_rule_id' => $automationRule->id, 'saved_automation_rule_token' => (string) Str::uuid(), ]); } /** * Soft delete the specified automation rule. */ public function destroy(AutomationRule $automationRule): RedirectResponse { $this->authorize('delete', $automationRule); $automationRule->delete(); return back(); } }