Laravel地图仅适用于第一个循环

时间:2019-01-31 12:34:02

标签: laravel collections

我有一个可以处理数组映射的集合。但是,只有在集合中只有一个对象的情况下,它才起作用。

我的功能:

$vacancies->map(function ($vacancie) {
            $vacancie['url'] = url(route('frontendShowVacancies', ['companyTitle' => urlencode($vacancie->company->title), 'vacancie' => $vacancie->id]));
            $vacancie['company']['images'][0]['url'] = url(route('companyImage', ['uuid' => $vacancie['company']['images'][0]['uuid']]));
            $vacancie['company']['image'] = $vacancie['company']['images'][0];
            $vacancie['company']['images'] = '';
            $vacancie['startDate'] = Carbon::parse($vacancie['startDate'])->format('d.m.Y');
            $vacancie['endDate'] = Carbon::parse($vacancie['endDate'])->format('d.m.Y');
            return $vacancie;
        });

我得到:

Uninitialized string offset: 0

它引用函数($vacancie['company']['images'][0]['url']...)中的第二行。我知道$vacancie['company']['images']是一个填充了0的数组。到底是怎么回事?为什么我会收到错误消息?

0 个答案:

没有答案