Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

LIxPacoGg's avatar

checkbox con Laravel y ajax

Hello, I wanted to know if someone could help me with a checkbox, I want to send records of a query (SQL) and save them in a table in MySQL. I'm new to using ajax and I don't understand very well, just like jquery, but I'm being guided by a video, this It is what I have of code, the query is manual SQL since there is no view to call it as a model, since I am extracting this data from a main system, and I do not have the permissions to create a view in the base SQL data

                         ```@foreach($ventas1 as $ventas)
                            <tr>
                                <td>
                                   <input type="checkbox" name="prodid[]" id="prod-id" value="mobile">
                                </td>
                                <td> {{ date("d-m-Y",strtotime($ventas->FECHA)) }}</td>
                            <td>   <input name="prodname[]" class="prod-name" id="prodname" value={{$ventas->FACTURA}} readonly> </td>
                             {{--   <td><input type="text">{{$ventas->MONEDA}}</td> --}}
                                <td>{{$ventas->NUMCTA}}</td>
                                <td>{{$ventas->CONCEPTO}}</td>
                                <td>{{$ventas->FACTURA}}</td>
                                <td>{{$ventas->DENOMINACION_SOCIAL}}</td>
                                <td>{{$ventas->VENDEDOR}}</td>
                                <td>${{$ventas->IMPORTE}}</td>
                                {{-- <td>${{$ventas->IMPORTEEXT}}</td> --}}
                            </tr>
                            @endforeach ```

My code in javascript

            $(document).ready(function(){
                $('.save_btn').on('click',function(e){
                    e.preventDefault();
                    const prodid= [];
                    $('.prod-id').each(function(){
                        if($(this).is(":checked")){
                            prodid.push($(this).val());
                        }
                    $.ajax({
                      url:'{{ route('save_data') }}',
                      type: 'POST',
                      data: {
                       "_token": "{{ csrf_token() }}",
                       prodid: prodid
                      },
                      success:function(response){
                      }
                    });
                });
            });
            });
        </script>```

Or if you could help me to do it with only php
0 likes
0 replies

Please or to participate in this conversation.