src/Forms/Form.php
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;
    }
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;
    }
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 ; }
Handle current request and start form data validation.

@param Request $request

@throws \Illuminate\Validation\ValidationException

@return $this
Handle current request and start form data validation .