The variable that stores a return only stores the first time of a loop

0
$campaign->images = array_map(function ($image) use($agencias) {
            $campaignImage = $this->campaignImageRepository->byImage($image->images_id)->first();
            $fileImage = Storage::get($image->path);
            $fileContent = base64_encode($fileImage);

            $image->image = $fileContent;
            if (!empty($campaignImage->code_agencies)) {
                $image->agency = $agencias->{$campaignImage->code_agencies};
                var_dump($image->agency->codigo);
            }
            return $image;
        }, $campaign->images()->get()->all());

I have this code that passes through campaign images and takes the related agencies, however $ campaignImage is only treated as an object the first time the loop is run, then the value is null

    
asked by anonymous 24.01.2018 / 15:54

0 answers