Laravel Where Collection

时间:2018-09-20 05:20:46

标签: arrays json laravel lumen laravel-collection

我在laravel收藏方面遇到了麻烦。这是我的脚本:

foreach($getResult->all()['results'] as $key => $val) {
  $colVal = collect($val);

  $dataDiff = [];
  $getWithoutLine = $colVal->except(['line_items']);
  $getDiff = $colVal->only(['line_items']);

  foreach($colVal->all()['line_items'] as $val1) {
    if ((int)$val1['quantity'] - (int)$val1['deliveries']['quantity'] > 0) {
      $getWithoutLine['status'] = 'partially_received';
      $dataDiff[] = $val1;
    }
  }

  $getWithoutLine['line_items'] = $dataDiff;
  //dd($getWithoutLine);
  $filtered = $getWithoutLine->whereStrict('status', 'submitted');
  //dd($filtered->all());
  $getFullCol[] = $filtered;
}

执行dd($getWithoutLine)时,收集如下所示:

Collection {#464
  #items: array:24 [
    "id" => "13c023aa-b471-4276-a0fc-a22d3677be91"
    "status" => "submitted"
    "date" => "2018-09-19"
    "time" => "11:54:22"
    "number" => "PO000003"
    "description" => "Pesanan Pembelian, Vendor 1"
    "supplier" => array:4 [
      "id" => null
      "code" => null
      "name" => null
      "classification" => null
    ]
    "term_of_payment" => array:6 [
      "due_date" => null
      "due_days" => 0
      "late_charge_rate" => 0.0
      "discount_date" => null
      "discount_days" => 0
      "early_discount_rate" => 0.0
    ]
    ...
    ...
  ]
}

但是执行dd($filtered->all())时结果为空。为什么会这样?

我不明白自己在做什么错。

======== 编辑

当我将dd($filtered->all())更改为dd($filtered)时,结果实际上是相同的:

Collection {#463
  #items: []
}

======= 编辑

当我将$filtered = $getWithoutLine->whereStrict('status', 'submitted');更改为$getWithoutLine->only('status');时,该收藏集开始工作...

Collection {#468
  #items: array:1 [
    "status" => "submitted"
  ]
}

0 个答案:

没有答案