| @@ -48,11 +48,14 @@ | ||
| 48 | 48 | |
| 49 | 49 | public function createLabel(Request $request, $board_id) |
| 50 | 50 | { |
| 51 | 51 | $board_id = absint($board_id); |
| 52 | - $labelData = $this->labelSanitizeAndValidate($request->only(['bg_color', 'color', 'label']), [ | |
| 53 | - 'bg_color' => 'required|string', | |
| 54 | - 'color' => 'required|string', | |
| 52 | + $labelData = Helper::sanitizeLabel($request->only(['bg_color', 'color', 'color_preset', 'label'])); | |
| 53 | + $hasPreset = !empty($labelData['color_preset']); | |
| 54 | + $labelData = $this->validate($labelData, [ | |
| 55 | + 'bg_color' => $hasPreset ? 'nullable|string' : 'required|string', | |
| 56 | + 'color' => $hasPreset ? 'nullable|string' : 'required|string', | |
| 57 | + 'color_preset' => 'nullable|string', | |
| 55 | 58 | 'label' => 'nullable|string', |
| 56 | 59 | ]); |
| 57 | 60 | |
| 58 | 61 | try { |
| @@ -142,11 +145,14 @@ | ||
| 142 | 145 | public function editLabelofBoard(Request $request, $board_id, $label_id) |
| 143 | 146 | { |
| 144 | 147 | $board_id = absint($board_id); |
| 145 | 148 | $label_id = absint($label_id); |
| 146 | - $labelData = $this->labelSanitizeAndValidate($request->only(['bg_color', 'color', 'label']), [ | |
| 147 | - 'bg_color' => 'required|string', | |
| 148 | - 'color' => 'nullable|string', | |
| 149 | + $labelData = Helper::sanitizeLabel($request->only(['bg_color', 'color', 'color_preset', 'label'])); | |
| 150 | + $isCustomSelection = array_key_exists('color_preset', $labelData) && $labelData['color_preset'] === ''; | |
| 151 | + $labelData = $this->validate($labelData, [ | |
| 152 | + 'bg_color' => $isCustomSelection ? 'required|string' : 'nullable|string', | |
| 153 | + 'color' => $isCustomSelection ? 'required|string' : 'nullable|string', | |
| 154 | + 'color_preset' => 'nullable|string', | |
| 149 | 155 | 'label' => 'nullable|string', |
| 150 | 156 | ]); |
| 151 | 157 | try { |
| 152 | 158 | $label = $this->labelService->editLabelofBoard($labelData, $label_id, $board_id); |