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/slenders.komma.pro/app/Komma/Routes/BreadcrumbComposer.php
<?php


namespace App\Komma\Routes;


use Illuminate\Support\Facades\Lang;
use Illuminate\View\View;

class BreadcrumbComposer
{
    /**
     * Bind data to the view.
     *
     * @param  View  $view
     * @return void
     */
    public function compose(View $view)
    {
        $breadcrumbList = [
            (object)[
                'route' => request()->root(),
                'name'  => __('site/breadcrumb.rootName'),
            ],
        ];

        // Use the server request URI, because we have changed the laravel request into our RESTfull way
        $requestPath = $_SERVER['REQUEST_URI'];

        // If root then we can already return
        if($requestPath == "/") {
            $view->with('breadcrumbList', $breadcrumbList);
            return;
        }

        // Remove the root slash, and explode into segments
        $requestPath = substr($requestPath, 1);
        $segments = explode('/', $requestPath);

        // Loop through the segments
        foreach ($segments as $index => $segment) {

            // Check if the segment has a translation defined.
            $translationKey = 'site/breadcrumb.' . $segment;
            $translation = __($translationKey);

            // If the key and translation are the same, we haven't defined a manual translation
            // Therefor we do the default conversion
            if($translation === $translationKey) {

                $translation = ucfirst($segment);
                $translation = str_replace('-', ' ', $translation);
            }

            // Append to the breadcrumb list
            $breadcrumbList[] = (object)[
                'route' => $breadcrumbList[$index]->route . '/' . $segment,
                'name' => $translation
            ];
        }

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