$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