input('role'); return [ 'isClient' => $role === UserRoleRegistry::get('client')->value, 'isProjectManager' => $role === UserRoleRegistry::get('project-manager')->value, 'isDevelopper' => $role === UserRoleRegistry::get('developper')->value, ]; } /** * Prepare the data for validation. * * @return void */ protected function extraPrepareForValidation(): void { [ 'isClient' => $isClient, 'isProjectManager' => $isProjectManager, 'isDevelopper' => $isDevelopper, ] = $this->resolveRoleFlags(); $this->merge([ 'gitlab_id' => $isProjectManager || $isDevelopper ? $this->input('gitlab_id') : null, 'sites' => $isClient ? $this->input('sites') : null, ]); } /** * Get the extra validation rules. * * @return array */ protected function extraRules(): array { [ 'isClient' => $isClient, 'isProjectManager' => $isProjectManager, 'isDevelopper' => $isDevelopper, ] = $this->resolveRoleFlags(); return [ 'gitlab_id' => $isProjectManager || $isDevelopper ? 'required|integer|min:1' : 'nullable|integer|min:1', 'sites' => $isClient ? 'required|array' : 'nullable|array', 'sites.*' => 'integer|exists:sites,id|distinct', ]; } /** * Get the extra attributes. * * @return array */ protected function extraAttributes(): array { return [ 'gitlab_id' => trans('validation.custom.gitlab_id'), 'sites' => trans_choice('models.classes.sites', \INF), ]; } }