redirector->back()->withInput()->withErrors($errors, $this->errorBag); } /** * Get the validation rules that apply to the request. * * @return array */ public function rules() { $rules = [ 'department_id' => 'nullable|exists:departments,id', 'manager_id' => 'nullable|exists:users,id', 'company_id' => ['nullable','exists:companies,id'] ]; switch ($this->method()) { // Brand new user case 'POST': $rules['first_name'] = 'required|string|min:1'; $rules['username'] = 'required_unless:ldap_import,1|string|min:1'; if ($this->request->get('ldap_import') == false) { $rules['password'] = Setting::passwordComplexityRulesSaving('store').'|confirmed'; } break; // Save all fields case 'PUT': $rules['first_name'] = 'required|string|min:1'; $rules['username'] = 'required_unless:ldap_import,1|string|min:1'; $rules['password'] = Setting::passwordComplexityRulesSaving('update').'|confirmed'; $rules['company_id'] = [new UserCannotSwitchCompaniesIfItemsAssigned()]; break; // Save only what's passed case 'PATCH': $rules['password'] = Setting::passwordComplexityRulesSaving('update'); $rules['company_id'] = [new UserCannotSwitchCompaniesIfItemsAssigned()]; break; default: break; } return $rules; } }