POST com Angularjs e Laravel

Asked

Viewed 116 times

0

I’m trying to send via POST to my backend Windows, but on the console it points out the error:

POST http://localhost:8000/new 500 (Internal Server Error) ! !

  • Here is my code from Angularjs

    <!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>
    
    <style type="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());
    
    }
    
  • Someone can help me?

  • Did you see what happens in the "Network" tab of your browser console? Only with this data is it impossible to say what happened, because error 500 can be n different things.

  • Please edit your question. And add more information about the error.

No answers

Browser other questions tagged

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