HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/SBogers10/somerenslust.komma.pro/app/KommaApp/Schemes/SchemeComposer.php
<?php

namespace App\KommaApp\Schemes;

use App\KommaApp\Images\ImageService;
use App\KommaApp\Schemes\Models\Scheme;
use Carbon\Carbon;
use Illuminate\View\View;

class SchemeComposer
{

    /**
     * Bind data to the view.
     *
     * @param  View  $view
     * @return void
     */
    public function compose(View $view)
    {
        $schemes = Scheme::where('active', 1)
            ->with('translation')
            ->get();

        foreach ($schemes as $scheme) $scheme->translation  = $this->decodeDynamicContent($scheme->translation);


        $view->with('schemes', $schemes);
    }

    private function decodeDynamicContent($translation)
    {
        $decodedJson = json_decode($translation->description);

        $dynamicBlocks = [];

        $imageController = new ImageService();

        foreach ($decodedJson as $dynamicElement){

            if(isset($dynamicElement->fileIds)) {
                $images = $imageController->getDynamicBlockImages( $dynamicElement->fileIds );
                $dynamicElement->images = $images;
            }


                $dynamicBlocks[] = $dynamicElement;
        }

        $translation->description = $dynamicBlocks;

        return $translation;
    }
}