POST 请求在浏览器中有效,但在邮递员中无效。SQLSTATE[23000]:完整性约束冲突:1048 列"name"不能为空



我正在编写 Laravel -AngularJS 应用程序,我调用的 post 方法正在浏览器中传递数据更新,在邮递员中我收到错误

SQLSTATE[23000]:完整性约束冲突:1048 列"name"不能为空

数据库也更新了,-我检查了它

工匠修补匠 .

我的代码可以在这里找到 AngularJS 不会显示(解析)在 Laravel5 中随 $http.get 一起提供的数据,带有索引.php 像这样更改:

<!DOCTYPE html>
<html lang=eng>
<head>
<meta charset="UTF-8">
  <title>Welcome </title>
  <!-- CSS -->
  <link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.0/css/bootstrap.min.css"> <!-- load bootstrap via cdn -->
  <link rel="stylesheet" href="//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.min.css"> <!-- load fontawesome -->
  <style>
    body    { padding-top:30px; }
/*    form    { padding-bottom:20px; }
*/  </style>
  <!-- JS -->
  <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>
    <script >

                angular.module('user1App', [
          ]);
          angular.module('user1App').controller('mainController', function($scope, $http) {
          $scope.user1Data = {};
          $http.get('api/v1/jokes').success(function(data) { 
          $scope.user1s = data; 
          });
          $scope.submitUser1 = function() {
              //$scope.loading = true;
              // save the comment. pass in comment data from the form
        $http({
        method: 'POST',
        url: 'api/v1/jokes',
        type: 'JSON',
        dataType: 'JSON',
        data: JSON.stringify($scope.user1Data)
        }).success(function(User1data) { 
          $scope.user1Data = {};
                 });
            };
          });
    </script>
</head>

<body   class="container" ng-app="user1App" ng-controller="mainController">

  <form name="newForm" ng-submit="submitUser1()"> <!-- ng-submit will disable the default form action and use our function -->
    <!-- NAME -->
    <div class="form-group">
      <input type="text" class="form-control input-sm" name="name" ng-model="user1Data.name" placeholder="Name" required>
    </div>
    <!-- COMMENT TEXT -->
    <div class="form-group">
      <input type="email" class="form-control input-lg" name="email" ng-model="user1Data.email" placeholder="Email" required>
    </div>
    <div class="form-group">
      <input type="tel" class="form-control input-lg" name="phon_number" ng-model="user1Data.phone_number" placeholder="Phone_number" required>
    </div>
    <!-- SUBMIT BUTTON -->
    <div class="form-group text-right"> 
      <button type="submit" class="btn btn-primary btn-lg" >Register</button>
    </div>
  </form>

  <div class="user1"  ng-repeat="user1 in user1s">
    <h3> <small>{{ user1.name }} , {{ user1.email }}</small></h3>
    <p>{{ user1.phone_number }}</p>
  </div>
</body>
</html>

我已经解决了这个问题。

我已经更改了方法 USer1控制器.php从这里:

   public function store(Request $request) {
        User1::create([
            'name' => $request->input('name'),
            'email' => $request->input('email'),
            'phone_number' => $request->input('phone_number')
        ]);
        return response()->json(['success' => true]);
    }

到那个 :

public function store(Request $request)
{       
        $this->validate($request , [
            'name' =>'required' ,
            'email' =>'required' ,
            'phone_number' =>'required' ,   
            ]);
        $user= new User1;
        $user->name = $request->name;
        $user->email =  $request->email;
        $user->phone_number =  $request->phone_number;
        $user->save();
    return response()->json(['success' => true]);
}

相关内容

  • 没有找到相关文章

最新更新