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/Eurotools/euro-tools.nl/app/KommaApp/Breadcrumb/BreadcrumbComposer.php
<?php


namespace App\KommaApp\Breadcrumb;

use App\KommaApp\Kms\Core\KmsInterface;
use App\KommaApp\Pages\PageService;
use Illuminate\Support\Facades\Config;

class BreadcrumbComposer {

    private $pageService;
    private $kms;

    /**
     * @return mixed
     */
    public function __construct(PageService $pageService)
    {
        $this->pageService = $pageService;
        $this->kms = \App::make(KmsInterface::class);
    }
    /**
     * Making the breadcrumb by getting the url segments
     *
     * @param $view
     */
    public function compose($view){

        $segments = \Request::segments();
        $breadCrumb = [];
        $url = '';
        $languages = \App::getSite()->languages;
        $language_shortnames = $languages->pluck('iso_2')->toArray();

        foreach ($segments as $key => $segment) {
            if(in_array($segment, $language_shortnames)){
                $url .= '/' . $segment;
                continue;
            }

            $text = $segment;
            $text = str_replace('-', ' ', $text);
            $url .= '/' . $segment;
            $breadCrumb[] = ['url_part' => $url , 'text' => $text];
        }


        $view->with('bread', $breadCrumb);
    }

}