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