merge([ 'newValues' => json_decode($this->input('jsonValue'), true), ]); } /** * Get the validation rules that apply to the request. */ public function rules(): array { $currentRange = request('range'); return [ 'jsonValue' => 'json', 'newValues' => 'required|array', 'newValues.*' => 'required|array', 'newValues.*.id' => 'required|exists:subranges,id', 'newValues.*.range_id' => function (string $attribute, mixed $value, \Closure $fail) use ($currentRange) { if ($value !== $currentRange->getKey()) { $fail("The {$attribute} is invalid."); } }, ]; } }