user()->is_admin; } /** * Get the validation rules that apply to the request. * * @return array|string> */ public function rules(): array { return [ 'new_split' => 'sometimes|string|max:255|min:1', 'split' => 'sometimes|array', ]; } public function after(): array { $splitScoreDefinition = $this->route('splitScoreDefinition'); return [ function (Validator $validator) use ($splitScoreDefinition) { if ($this->has('new_split')) { $existingSplitNames = collect($splitScoreDefinition->splits) ->pluck('name') ->toArray(); if (in_array($this->new_split, $existingSplitNames)) { $validator->errors()->add( 'new_split', 'This split name already exists in this definition.' ); } } }, ]; } }