How to pass a data from Javascript to Php Laravel

0

What I'm trying to do is a function in javascript that sends a simple data to a laravel controller and then upload it to the database, the problem I have is that until now I could not find a way to send that data, I always get error 500.

controller in laravel:

 public function crearRegistro(Request $request){

    $registro = new Registro();
    $registro->indicador = $request->indicador;
    $registro->save();

}

Function in Javascript:

 $scope.calculoIndicador = function(){
  $http.post("/calculoIndicador")
  .then(function(response) {
    });
  $scope.indicador = 5 +5;
   alert('Se ha guardado correctamente');

}

I am using the javascript function with a button in the view.

<input class="btn btn-success" style="" ng-click="calculoIndicador()" 
 type="submit" value="Enviar"/> 

And I also have everything ready on the route

    
asked by Talked 01.05.2018 в 17:25
source

1 answer

1

Your problem is that you are not passing the indicator parameter to the controller. Try it like this:

$http.post("/calculoIndicador", {indicador: 10})

The number 10 can be replaced by any variable you want.

    
answered by 01.05.2018 / 19:15
source