Laravel 8 - bootstrapswitch - Change output before sending to Bank

Asked

Viewed 27 times

-1

Next people I’m new to Laravel and I’m half crazy with that kkk Help

I am sending a Form to my Database and using a bootstrapswitch checkbox. Follow my INPUT:

<div class="col-md-12 col-xs-12">
     <div class="form-group text-center  ">
            <input type="checkbox" name="os_tipo_id" data-bootstrap-switch
                  data-on-text="SELF" data-off-text="FAN COIL"
                  data-off-color="primary" class="os_tipo_id"
                  data-on-color="success"  id="FANSELF">
     </div>
</div>

My JS

        $(".os_tipo_id").on('switchChange.bootstrapSwitch',function(e, state){var value = state ? '2' : '1';console.log(value);});

No console os Valores saem bonitinho, mas qdo vai pro banco não vai os valores que inseri no for each

inserir a descrição da imagem aqui

IT is coming out as ON and I need to send the "os_tipo_id"

How do I make Laravel pick up the value q I’m doing on JS and send straight to the bank?

In case someone needs

My Controller Store

inserir a descrição da imagem aqui

NOTE: my relationships are all right the problem is that q does not send the correct value. And I do not know how to do more.

I’m ultilizing this library

<script src="https://adminlte.io/themes/v3/plugins/bootstrap-switch/js/bootstrap-switch.min.js"></script>

1 answer

-1


You can treat on request:

$idchamado['os_tipo_id'] = $request->os_tipo_id == 'on' ? '2' : '1';

It is advisable to create an Ordemservicostorerequest class and process the data there.

class OrdemServicoStoreRequest extends FormRequest
    {
        public function rules()
        {
            return [
                'client_id'           => 'required',
                'users_id'            => 'required',
                'tipo_atendimento_id' => 'required',
                'data'                => 'required|date',
                'os_tipo_id'          => 'required'
            ];
        }

        public function authorize()
        {
            return TRUE;
        }


        protected function prepareForValidation()
        {
            $this->merge([
                'os_tipo_id' => $this->os_tipo_id == 'on' ? '2' : '1',
            ]);
        }
    }

Browser other questions tagged

You are not signed in. Login or sign up in order to post.