间接修改重载属性Illuminate \ Http \ Request :: $ values无效

时间:2018-02-26 15:55:13

标签: php laravel foreach

我正在尝试更改集合。但错误已经在foorlooad上,即使没有内容错误apears

foreach ($request->values as $id => &$value) {
        $values[1] = $this->repository->getById($request->id)->values[$id][1];
        $values[2] = $this->repository->getById($request->id)->values[$id][2];
        $values[3] = $this->repository->getById($request->id)->values[$id][3];
        $values[4] = $this->repository->getById($request->id)->values[$id][4];
        //dd($value);
    }

1 个答案:

答案 0 :(得分:0)

我重构了我的代码来做dame但是使用了一个新数组而不是填充现有的$ request

foreach ($request->values as $id => $value) {
        $values[$id][0] = $request->values[$id][0];
            for ($i = 1; $i <= 4; $i++) {
                if (isset($this->repository->getById($request->id)->values[$id][$i])) {
                    $values[$id][$i] = $this->repository->getById($request->id)->values[$id][$i];
                } else {
                    $values[$id][$i] = '';
                }
            }
        }