input('role') == UserRolesEnum::admin->value()) { $this->merge([ 'tenants' => null ]); } } /** * Get the validation rules that apply to the request. * * @return array */ public function rules(): array { $isClient = $this->input('role') == UserRolesEnum::client->value(); return [ 'first_name' => 'required|string|min:3|max:255', 'last_name' => 'required|string|min:3|max:255', 'email' => [ 'required', 'email:rfc,strict,dns,spoof,filter', Rule::unique('users', 'email') ], 'role' => ['required', new Enum(UserRolesEnum::class)], 'tenants' => $isClient ? 'required|array' : 'nullable|array', 'tenants.*' => $isClient ? 'required|array' : 'nullable|array', 'tenants.*.id' => $isClient ? 'required|exists:tenants,id' : 'nullable|exists:tenants,id', ]; } /** * Get custom attributes for validator errors. * * @return array */ public function attributes(): array { return [ 'first_name' => trans('validation.attributes.first_name'), 'last_name' => trans('validation.attributes.last_name'), 'email' => trans('validation.attributes.email'), 'role' => trans('validation.attributes.role'), 'tenants' => Str::of(trans('models.classes.tenant'))->plural(), ]; } }