Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 使用AngularJS将表单数据传递给laravel控制器_Php_Angularjs_Laravel - Fatal编程技术网

Php 使用AngularJS将表单数据传递给laravel控制器

Php 使用AngularJS将表单数据传递给laravel控制器,php,angularjs,laravel,Php,Angularjs,Laravel,我这里有一个简单的代码,希望将数据传递给laravel控制器,以便将其存储到数据库中。我的代码是: AccountController.php public function store(Request $request) { Account::create(array( 'email' => $request->get('email'), 'name' => $request->get('text'

我这里有一个简单的代码,希望将数据传递给laravel控制器,以便将其存储到数据库中。我的代码是:

AccountController.php

public function store(Request $request)
    {
        Account::create(array(
            'email' => $request->get('email'),
            'name' => $request->get('text'),
            'age' => $request->get('age'),
        ));

        return ['success' => true];
    }
刀片

<form ng-submit="newAccount()">
          <div class="form-group">
            <label for="email">Email address</label>
            <input type="email" class="form-control" id="email" ng-model="accountData.email">
          </div>

          <div class="form-group">
            <label for="fullname">Full Name</label>
            <input type="email" class="form-control" id="fullname" ng-model="accountData.name">
          </div>

          <div class="form-group">
            <label for="age">age</label>
            <input type="email" class="form-control" id="age" ng-model="accountData.age">
          </div>
</form>

正如您在我的
app.js
中所看到的,我一直在思考如何从刀片服务器的文本框中获取数据。有没有一个简单的方法可以做到这一点?谢谢。

非常简单,您只需添加一个对象以通过POST请求即可。Laravel将从1到1选择这些变量

var app = angular.module('accountsApp', []);

app.controller('accountsCtrl', function($scope, $http) {

 $scope.newAccount = function() {
      //add data
      $http.post('/api/accounts', 
      {
        email: $scope.accountData.email,
        text: $scope.accountData.text,
        age: $scope.accountData.age

      }).
      .success(function(response) {
        scope.accounts = response;
      })
      .error(function(response) {
        console.log(response);
      });

    };

});

为什么不使用jquery来处理这么简单的事情呢?你想通过ajax或提交表单动作将其发送给控制器,因为我想学习Angular@Patricio,那么你可能会有另一个,也许你遇到了Laravel的质量分配异常。检查控制台中的“网络”选项卡发生了什么。我现在看到问题了,$scope.accountData.email无法解决问题。一定是什么东西。我尝试了一个静态值,它工作了。例如email:'test'@FewFlyBy很抱歉反应太晚,我知道你做错了什么,所有的表单类型都是

var app = angular.module('accountsApp', []);

app.controller('accountsCtrl', function($scope, $http) {

 $scope.newAccount = function() {
      //add data
      $http.post('/api/accounts', 
      {
        email: $scope.accountData.email,
        text: $scope.accountData.text,
        age: $scope.accountData.age

      }).
      .success(function(response) {
        scope.accounts = response;
      })
      .error(function(response) {
        console.log(response);
      });

    };

});