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/MeulendijkFijnmetaal/meulendijkfijnmetaal.nl/app/Http/Controllers/Controller.php
<?php

namespace App\Http\Controllers;

use App\KommaApp\Images\ImageService;
use App\KommaApp\Languages\LanguageService;
use App\KommaApp\Pages\PageService;
use App\KommaApp\Routes\Models\Route;
use App\KommaApp\Shop\Categories\Kms\CategoryService;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;

abstract class Controller extends BaseController
{
    use AuthorizesRequests, DispatchesJobs, ValidatesRequests;

    protected $languageService;
    protected $pageService;
    protected $links;

    protected $baseViewPath = 'site.';

    public function __construct()
    {
        $this->preventRestRouteFromWorking();
        $this->languageService = new LanguageService();
        $this->pageService = new PageService();
        $this->links = $this->pageService->getAllTranslatedPageRoutes();
    }

    /*
     * This function should only be temporary until dynamic blocks is rewrite to it's own blocks
     * instead of using json
     */
    protected function decodeDynamicContent($translation)
    {
        $decodedJson = json_decode($translation->description);

        $dynamicBlocks = [];
        $dynamicGroups = [];

        $imageController = new ImageService();

        foreach ($decodedJson as $dynamicElement){

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

            // Order dynamic blocks
            if($dynamicElement->code_name != '' ){ // If dynamic block has code name then add it to the translation
                $translation->{$dynamicElement->code_name} = $dynamicElement;
            } elseif($dynamicElement->view != ''){ // If dynamic block has view then add it to dynamic groups
                if( !isset($dynamicGroups[$dynamicElement->view])) $dynamicGroups[$dynamicElement->view] = [];
                $dynamicGroups[$dynamicElement->view][] = $dynamicElement;
            } else{ // Else just add them to the default dynamic content
                $dynamicBlocks[] = $dynamicElement;
            }
        }

        $translation->groups = $dynamicGroups;
        $translation->description = $dynamicBlocks;

        return $translation;
    }

    /**
     * This method will prevent that REST routes are working with the application
     * They should be resolved by the middleware
     *
     */
    private function preventRestRouteFromWorking(){
        if (\App::runningInConsole()) return;

        $request = request();

        // Normally it should be resolved or it's a hard defined route
        // Example. contact/process
        if(isset($request->resolved) && $request->resolved) return;
        else{
            // Get segments and path
            $path = \Request::path();
            $segments = \Request::segments();

            // Check if current path is a restfull path, or the first segment of it is
            $restRoutes = Route::whereIn('route', [$path, $segments[0]])
                ->get();

            // Rest routes should be empty, or it already should be resolved
            if($restRoutes->count() == 0) return;
            else{
                // If production throw 404
                if(\App::environment() == 'production') throw abort(404);

                // Else Argument Exception with explanation
                else throw new \InvalidArgumentException("Route path or the first segment is listed as an REST route");
            }
        }
    }
}