laravel driver to receive data from ajax

0

I'm trying to insert data from an Ajax but it gives me an HTTP500 error, I suppose it is from the controller and I wonder what modifications the controller needs to receive the data correctly?

Driver

public function controladorprueba(Request $request)
    {

        $product = Product::create($request->all());

        return Response::json($product);

    }

Ajax

<script>
    $(document).ready(function(){
  $(document).on('submit', '#formularioprueba', function() {

      //Obtengo datos formulario.
      var data = $(this).serialize();

      //AJAX.
      $.ajax({
          type : 'POST',
          url  : "{{ route('products.prueba1') }}",
          data:  data,

          success:function(data) {
              $('#respuesta').html(data).fadeIn();
          }
      });
      return false;
 });
});
    </script>

Route

Route::post('products/prueba1', '[email protected]')->name('products.controladorprueba');
    
asked by Lendy Rodriguez Silva 09.11.2018 в 19:17
source

0 answers