I'm trying to send via POST to my laravel backend, but on the console it points to the error:
POST link 500 (Internal Server Error)! !
-
Here's my AngularJS code
<!DOCTYPE html> <html ng-app="myApp"> <head> <link rel="stylesheet" type="text/css" href="css/app.css"> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"></script></head><body><styletype="text/css"> .top50{ margin-top: 50px; } </style> <div ng-controller="myCtrl"> <div class="container"> <form ng-submit="enviar()"> <div class="row"> <div class="col-md-3"> <input type="" ng-model="pedido.total" name="nome"> {{nome}} </div> <div class="col-md-3"> <input type="" ng-model="pedido.quantidade_produtos" name="email"> {{user}} </div> <div class="col-md-3"> <button type="submit" class="btn btn-success">Cadastrar</button> </div> </div> </form> {{pedido}} <table class="table top50"> <thead> <tr> <td>ID</td> <td>Total</td> <td>Qnt. Produtos</td> </tr> </thead> <tbody> <tr ng-repeat="t in teste"> <td>{{t.id}}</td> <td>{{t.total}}</td> <td>{{t.quantidade_produtos}}</td> </tr> </tbody> </table> </div> </div> <script> var app = angular.module('myApp', []); app.controller('myCtrl', function($scope, $http) { $scope.pedido= {}; $scope.enviar = function(){ $http({ url: 'http://localhost:8000/novo', method: "POST", data: $scope.pedido }) .then(function(response) { // success }, function(response) { // optional // failed }); } $http.get("http://localhost:8000/angular") .then(function(response) { setTimeout(function () { $scope.$apply(function () { $scope.teste = response.data; }); }, 0); }); }); </script> </script> </body> </html>
-
This is my backend:
public function adiciona(Request $request){ Pedidos::create($request->all()); }