Validate public and private forms indifferently, and update info if validations are OK.

@param \Illuminate\Http\Request $request
772997
private function mainUpdateProfile($request)
    {
        $this->validate($request, [
            'name'              => 'required|min:3|max:191',
            'current_password'  => 'required',
        ]);

        $user = User::findOrFail(Auth::id()); // To use Laralum user model

        if (!Hash::check($request->current_password, $user->password)) {
            // Password incorrect
            return __('laralum_profile::general.incorrect_password'); // Update error: incorrect password
        }
        if ($request->hasFile('picture')) {
            $this->validate($request, [
                'picture' => 'image|max:5120',
            ]);

            if ($request->file('picture')->isValid()) {
                $request->file('picture')->move(public_path('/avatars'), md5($user->email));
            } else {
                return __('laralum_profile::general.image_not_valid'); // Update error: image not valid
            }
        } else {
            if ($user->hasAvatar()) {
                if (!$request->save_picture) {
                    File::delete(public_path('/avatars/'.md5($user->email)));
                }
            }
        }
        if ($request->password) {
            $this->validate($request, [
                'password' => 'min:6|confirmed',
            ]);
            $user->update(['password' => $request->password]);
        }

        if ($request->name) {
            $user->update(['name' => $request->name]);
        }

        return 0; // Updated completed okai
    }
501662
protected function validateRequest(Request $request)
    {
        $validationErrors = array();

        if (strlen($request->getApiMethod()) == 0)
        {
            $validationErrors[] = 'Request api method is empty';
        }

        if (strlen($request->getEndPoint()) == 0 && strlen($request->getEndPointGroup()) === 0)
        {
            $validationErrors[] = 'Request end point is empty and request end point group is empty. Set one of them.';
        }

        if (strlen($request->getEndPoint()) > 0 && strlen($request->getEndPointGroup()) > 0)
        {
            $validationErrors[] = 'Request end point was set and request end point group was set. Set only one of them.';
        }

        if (count($request->getRequestFields()) === 0)
        {
            $validationErrors[] = 'Request data is empty';
        }

        if (!Validator::validateByRule($request->getGatewayUrl(), Validator::URL, false))
        {
            $validationErrors[] = 'Gateway url does not valid in Request';
        }

        if (!empty($validationErrors))
        {
            throw new ValidationException("Some Request fields are invalid:\n" .
                                          implode(";\n", $validationErrors));
        }
    }
492551
private function createRequest(Request $request = null): void
    {
        if (!$this->request && is_null($request)) {
            $request = ServerRequest::fromGlobals()
                ->withParsedBody(json_decode(file_get_contents('php://input')));
        }

        $this->container->set(Request::class, $request);
        $this->request = $request;
    }
31962
public function update(Request $request)
    {
        $this->validate($request, [
            'password' => 'required|confirmed|min:6',
        ]);

        $request->user()->update([
            'password' => bcrypt($request->password),
        ]);
    }
502486
public function handleRequest(Request $request): FormInterface
    {
        $fields = $this->repository->all();

        $this->validator = $this->validation->make(
            $request->all(),
            $this->getFormRules($fields),
            $this->getFormMessages($fields),
            $this->getFormPlaceholders($fields)
        );

        $data = $this->validator->valid();

        // Attach the errors message bag to each field.
        // Set each field value.
        // Update the DTO instance with form data if defined.
        array_walk($fields, function ($field) use ($data) {
            /** @var $field BaseType */
            $field->setErrorMessageBag($this->errors());

            // Set the field value. Each field has its own data transformer so when we
            // call the field getValue() method later on, we're sure to fetch a correct
            // formatted value.
            $field->setValue(Arr::get($data, $field->getName()));

            // DTO
            if (! is_null($this->dataClass) && is_object($this->dataClass) && $field->getOption('mapped')) {
                $this->dataMapper->mapFromFieldToObject($field, $this->dataClass);
            }

            // By default, if the form is not valid, we keep populating fields values.
            // In the case of a valid form, by default, values are flushed except if
            // the "flush" option for the form has been set to true.
            if ($this->validator->fails()) {
                if ($field->error()) {
                    // Add invalid CSS classes.
                    $field->addAttribute('class', 'is-invalid');
                } else {
                    // Add valid CSS classes and validate the field.
                    $field->addAttribute('class', 'is-valid');
                }
            } else {
                // Validation is successful, we can flush fields value at output.
                if ($this->getOption('flush', false)) {
                    $field['flush'] = true;
                }
            }
        });

        return $this;
    }
1265220
protected function _validateAndUnsetTokenField(ServerRequest $request)
    {
        if (in_array($request->getMethod(), ['PUT', 'POST', 'DELETE', 'PATCH']) || $request->getData()) {
            $this->_validateToken($request);
            $body = $request->getParsedBody();
            if (is_array($body)) {
                unset($body[$this->_config['field']]);
                $request = $request->withParsedBody($body);
            }
        }

        return $request;
    }
619942
public function validate(Request $request)
    {
        $this->validateUsername($request);
        $this->validatePassword($request);
        $this->validateEmail($request);
        $this->validateGender($request);

        return $this->isValid;
    }
872337
public function validateForm(\Illuminate\Http\Request $request, ModelConfigurationInterface $model = null)
    {
        $this->getTabs()->each(function ($tab) use ($request, $model) {
            $tabId = $request->get('sleeping_owl_tab_id');

            if ($tab instanceof FormInterface && $tab->getName() == $tabId) {
                $tab->validateForm($request, $model);
            }
        });
    }
650554
protected function validateRequestParameters(Request $request)
    {
        $data = $request->request->all();
        if (isset($data['id'])) {
            unset($data['id']);
        }

        // we explicitly do not load existing data; an edit is a PUT and should supply all valid data!
        $this->form->submit($data);
        if (!$this->form->isValid()) {
            throw new BadRequestHttpException($this->form->getErrorsAsString());
        }

        return $this->form;
    }
75080
public function update(UpdateRequest $request)
    {
        $this->addDefaultGeoFields(\Request::input('template'));
        $this->useTemplate(\Request::input('template'));

        return parent::updateCrud();
    }
667875
public function invalidate(Request $request)
    {
        $modified = false;
        $key = $this->getCacheKey($request);

        $entries = [];
        foreach ($this->getMetadata($key) as $entry) {
            $response = $this->restoreResponse($entry[1]);
            if ($response->isFresh()) {
                $response->expire();
                $modified = true;
                $entries[] = [$entry[0], $this->persistResponse($response)];
            } else {
                $entries[] = $entry;
            }
        }

        if ($modified && false === $this->save($key, serialize($entries))) {
            throw new \RuntimeException('Unable to store the metadata.');
        }
    }
934611
public function isValid (Request $request)
		{
			$parsed = $this->parseRouteRequest($request);

			return $this->getBaseUri($request) !== null
				&& preg_match('#^' . preg_quote(rtrim($this->getBaseUri($request), '/'), '#') . '#', rtrim($request->getUri(false), '/'))
				&& $this->getController($request)->respondsTo($parsed['method'], $parsed['arguments']);
		}
1374959
public function write($request)
    {
        if ($this->isComplete) {
            throw new ValidationException("Cannot call write() after streaming call is complete.");
        }
        if ($this->writesClosed) {
            throw new ValidationException("Cannot call write() after calling closeWrite().");
        }
        $this->call->write($request);
    }
1103696
protected function checkForAlternateVerbs($request)
	{
		$methods = array_diff(Router::$verbs, array($request->getMethod()));

		// Here we will spin through all verbs except for the current request verb and
		// check to see if any routes respond to them. If they do, we will return a
		// proper error response with the correct headers on the response string.
		$others = array();

		foreach ($methods as $method)
		{
			if ( ! is_null($this->check($this->get($method), $request, false)))
			{
				$others[] = $method;
			}
		}

		return $others;
	}
1114781
public function isValid(Request $request)
    {
        $arguments = $this->method === "GET" ? $request->get : $request->post;
        $files = $request->files;

        if (!$this->validate($arguments, $files))
            return false;

        $params = ['form' => $this, 'request' => $request, 'valid' => true, 'arguments' => $arguments];
        $params = TypedDictionary::wrap($params);
        $params->setType('errors', Type::ARRAY);
        $result = Hook::execute('Wedeto.HTTP.Forms.Form.isValid', $params);

        if (!$result['valid'])
        {
            foreach ($result['errors'] as $field => $errors)
            {
                if ($errors instanceof Dictionary)
                    $this->errors[$field] = $errors->toArray();
            }
            return false;
        }

        unset($this->form_elements[Nonce::getParameterName()]);
        unset($this->form_elements['_form_name']);

        return true;
    }
1110361
public function save(\Illuminate\Http\Request $request)
    {
        $this->setModelAttribute($this->getValueFromRequest($request));
    }
1120690
private function isValidCsrfToken(Request $request): bool
    {
        $csrfTokenValue = $request->headers->get(self::CSRF_TOKEN_HEADER);

        return $this->csrfTokenManager->isTokenValid(
            new CsrfToken('authenticate', $csrfTokenValue)
        );
    }