Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/11.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 为什么foreach循环中的Laravel集合总是拾取最后一个数组?_Php_Laravel_Foreach_Collections - Fatal编程技术网

Php 为什么foreach循环中的Laravel集合总是拾取最后一个数组?

Php 为什么foreach循环中的Laravel集合总是拾取最后一个数组?,php,laravel,foreach,collections,Php,Laravel,Foreach,Collections,where子句条件后有12个作业行。因此,我使用foreach语句获得12组属性ID。总共有大约500个属性被分成12组(数量不同)。最后一个数组有40个属性ID。我想将所有500个属性ID都放入$attributesId中,但这段代码只获取最后40个属性ID(使用dd查看)。我认为collect()方法一直在将新集合替换为$attributesId,但我不知道如何累计插入它们。其他一切都可以。请帮忙 $jobLines = JobLine::where('job_id', $job->i

where子句条件后有12个作业行。因此,我使用foreach语句获得12组属性ID。总共有大约500个属性被分成12组(数量不同)。最后一个数组有40个属性ID。我想将所有500个属性ID都放入$attributesId中,但这段代码只获取最后40个属性ID(使用dd查看)。我认为collect()方法一直在将新集合替换为$attributesId,但我不知道如何累计插入它们。其他一切都可以。请帮忙

$jobLines = JobLine::where('job_id', $job->id)
            ->whereHas('jobType', function ($q) {
                $q->where('code', 'Job_Code');
            })
            ->get();

foreach ($jobLines as $jobLine) {
     $jobChildren = JobTypeChild::all();
     $attributesId = collect($jobLine->attributes->toArray());
        ->pluck('job_type_attribute_id');

     $this->jmAttributes = JobTypeAttribute::whereIn(
           'job_type_attributes.id',
           $attributesId
           )->join(
                    ...table columns joining
                )
            ->where('job_line_id', $jobLine->id)
            ->pluck(
                 'job_line_attributes.value',
                 'attribute_fields.name'
             )
             ->toArray();
}
dd($attributesId);

因此,首先您要覆盖每个循环中的
$attributesId
变量也是
collect($jobLine->attributes->toArray());->>Pull('job_type_attribute_id')偶数有效