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;
}
}