如何从一个返回集合的帖子更新多个记录?

时间:2015-11-17 22:17:22

标签: angularjs ajax laravel-5.1

我有一个AngularJS表单,它使用ng-repeat和ng-form填充可以在此处标记为的用户列表。

我现在正在尝试使用AJAX将更新的字段提交给Laravel。

我的表单请求正在尝试POST一个集合并为多个记录更新一列。似乎没有发生任何事情,没有错误。

我怀疑我的方法有问题。

  public function setRoster(Request $request, $id) {
            $players[] = $request;
            foreach ($players as $player) {
                Player::where('playerId', $player->playerId)
                ->update(array('gamesPlayed' => $id));
            }
        }

有什么想法吗?谢谢!

这是来自POST的JSON

Request {#39
  #json: ParameterBag {#31
    #parameters: array:1 [
      "players" => array:22 [
        0 => array:15 [
          "playerId" => 1
          "teamId" => "6"
          "number" => "2"
          "position" => "unknown"
          "gamesPlayed" => ""
          "tempNumbers" => ""
          "firstName" => "Tom"
          "lastName" => "Travis"
          "dob" => "1968-10-01"
          "email" => "tom@hotmail.com"
          "mobile" => ""
          "photo" => "headshot.jpg"
          "created_at" => "-0001-11-30 00:00:00"
          "updated_at" => "-0001-11-30 00:00:00"
          "onIce" => true
        ]

依旧......

所以基于反馈,我试过了这个;

foreach ($request as $player) {
        Player::where('playerId', $player['playerId'])->update('gamesPlayed', '=', $id);
    }

现在返回此错误;

不能使用Symfony \ Component \ HttpFoundation \ ParameterBag类型的对象作为数组

0 个答案:

没有答案