File: /var/www/ipsremont-demo/app/Http/ViewComposers/BreadCrumbComposer.php
<?php
namespace App\Http\ViewComposers;
use Illuminate\View\View;
class BreadCrumbComposer
{
public function compose(View $view)
{
return $view->with('breadCrumb', $this->getbreadCrumb());
}
public function getbreadCrumb()
{
$currrentPath = request()->route()->action;
$array = $this->breadCrumb();
$breadCrumb = [];
foreach ($array as $keys => $b) {
if (isset($b['children'])) {
if ($b['route'] == $currrentPath['as']) {
array_push($breadCrumb, $b);
}
foreach ($b['children'] as $key => $child) {
if ($child['route'] == $currrentPath['as']) {
array_push($breadCrumb, $child);
array_push($breadCrumb, $array[$keys]);
}
}
} else {
if ($b['route'] == $currrentPath['as'] && $b['prefix'] != 'main') {
array_push($breadCrumb, $b);
}
}
}
array_push($breadCrumb, $this->getMain());
if ($breadCrumb[0]['type'] == 'dynamic') {
$param = (array)request()[$breadCrumb[0]['field']];
$breadCrumb[0]['value'] = $param[0];
}
return array_reverse($breadCrumb);
}
public function getMain()
{
foreach ($this->breadCrumb() as $b) {
if ($b['prefix'] == 'main')
return $b;
}
}
public function breadCrumb()
{
return [
[
"name" => "breadCrumb.main",
"route" => "dashboard",
"prefix" => "main",
"type" => "statical"
],
[
"name" => "breadCrumb.profile",
"route" => "profile.edit",
"prefix" => "profile",
"type" => "statical",
"children" => [
[
"name" => "breadCrumb.companyShow",
"route" => "profile.company.show",
"prefix" => "profile",
"type" => "statical"
],
[
"name" => "breadCrumb.companyEdit",
"route" => "profile.company.edit",
"prefix" => "profile",
"type" => "statical"
],
[
"name" => "breadCrumb.companyAdd",
"route" => "profile.company.add",
"prefix" => "profile",
"type" => "statical"
],
],
],
[
"name" => "breadCrumb.branches",
"route" => "branches",
"prefix" => "branches",
"type" => "statical",
"children" => [
[
"name" => "breadCrumb.branchesCreate",
"route" => "branches.create",
"prefix" => "branches",
"type" => "statical"
],
[
"name" => "breadCrumb.branchesEdit",
"route" => "branches.edit",
"prefix" => "branches",
"type" => "dynamic",
"field" => "id"
],
[
"name" => "breadCrumb.branchesImport",
"route" => "branches.import",
"prefix" => "branches",
"type" => "statical"
],
]
],
[
"name" => "breadCrumb.users",
"route" => "users.index",
"prefix" => "users",
"type" => "statical",
"children" => [
[
"name" => "breadCrumb.usersCreate",
"route" => "users.create",
"prefix" => "users",
"type" => "statical"
],
[
"name" => "breadCrumb.usersEdit",
"route" => "users.edit",
"prefix" => "users",
"type" => "dynamic",
"field" => "id"
]
]
],
[
"name" => "breadCrumb.services",
"route" => "services.index",
"prefix" => "services",
"type" => "statical",
"children" => [
[
"name" => "breadCrumb.servicesCreate",
"route" => "services.create",
"prefix" => "services",
"type" => "statical"
],
[
"name" => "breadCrumb.servicesEdit",
"route" => "services.edit",
"prefix" => "services",
"type" => "dynamic",
"field" => "id"
],
[
"name" => "breadCrumb.servicesShow",
"route" => "services.show",
"prefix" => "services",
"type" => "dynamic",
"field" => "id"
],
[
"name" => "breadCrumb.servicesUserEdit",
"route" => "services.users.edit",
"prefix" => "services",
"type" => "dynamic",
"field" => "id"
],
[
"name" => "breadCrumb.importServices",
"route" => "services.import",
"prefix" => "services",
"type" => "static"
],
[
"name" => "breadCrumb.importPrice",
"route" => "services.price.form",
"prefix" => "services",
"type" => "dynamic",
"field" => "id"
],
[
"name" => "breadCrumb.importLeftovers",
"route" => "services.leftovers.form",
"prefix" => "services",
"type" => "dynamic",
"field" => "id"
],
]
],
[
"name" => "breadCrumb.warehouses",
"route" => "warehouses.index",
"prefix" => "warehouses",
"type" => "statical",
"children" => [
[
"name" => "breadCrumb.warehousesCreate",
"route" => "warehouses.create",
"prefix" => "warehouses",
"type" => "statical"
],
[
"name" => "breadCrumb.warehousesEdit",
"route" => "warehouses.edit",
"prefix" => "warehouses",
"type" => "dynamic",
"field" => "id"
]
]
],
[
"name" => "breadCrumb.settings",
"route" => "settings.index",
"prefix" => "settings",
"type" => "statical",
],
[
"name" => "breadCrumb.users",
"route" => "emails.index",
"prefix" => "emails",
"type" => "statical",
"children" => [
[
"name" => "emails." . (request()->event ?? ''),
"route" => "emails.users.edit",
"prefix" => "emails",
"type" => "dynamic",
"field" => "event"
],
]
],
[
"name" => "breadCrumb.orders",
"route" => "emails.orders",
"prefix" => "emails",
"type" => "statical",
"children" => [
[
"name" => "emails." . (request()->event ?? ''),
"route" => "emails.orders.edit",
"prefix" => "emails",
"type" => "dynamic",
"field" => "event",
],
]
],
[
"name" => "breadCrumb.repairs",
"route" => "emails.repairs",
"prefix" => "emails",
"type" => "statical",
"children" => [
[
"name" => "emails." . (request()->event ?? ''),
"route" => "emails.repairs.edit",
"prefix" => "emails",
"type" => "dynamic",
"field" => "event"
],
]
],
[
"name" => "breadCrumb.address",
"route" => "emails.address",
"prefix" => "emails",
"type" => "statical",
"children" => [
[
"name" => "emails." . (request()->event ?? ''),
"route" => "emails.address.edit",
"prefix" => "emails",
"type" => "dynamic",
"field" => "event"
],
]
],
[
"name" => "breadCrumb.emailsColumntitle",
"route" => "emails.columntitle",
"prefix" => "emails",
"type" => "statical",
],
[
"name" => "breadCrumb.emailsSent",
"route" => "emails.list",
"prefix" => "emails",
"type" => "statical",
"children" => [
[
"name" => "breadCrumb.emailsShow",
"route" => "emails.list.show",
"prefix" => "emails",
"type" => "dynamic",
"field" => "id"
],
]
],
[
"name" => "breadCrumb.constructor",
"route" => "constructor.index",
"prefix" => "constructor",
"type" => "statical",
"children" => [
[
"name" => "breadCrumb.constructorCopy",
"route" => "constructor.copy",
"prefix" => "constructor",
"type" => "dynamic",
"field" => "id",
],
[
"name" => "breadCrumb.constructorEdit",
"route" => "constructor.edit",
"prefix" => "constructor",
"type" => "dynamic",
"field" => "id"
]
]
],
[
"name" => "breadCrumb.parts",
"route" => "parts.index",
"prefix" => "parts",
"type" => "statical",
"children" => [
[
"name" => "breadCrumb.partsShow",
"route" => "parts.show",
"prefix" => "parts",
"type" => "dynamic",
"field" => "id"
],
]
],
[
"name" => "breadCrumb.categories",
"route" => "categories.index",
"prefix" => "categories",
"type" => "statical",
"children" => [
[
"name" => "breadCrumb.categoriesCreate",
"route" => "categories.create",
"prefix" => "categories",
"type" => "statical"
],
[
"name" => "breadCrumb.categoriesEdit",
"route" => "categories.edit",
"prefix" => "categories",
"type" => "dynamic",
"field" => "id"
],
[
"name" => "breadCrumb.categoriesImport",
"route" => "categories.import",
"prefix" => "categories",
"type" => "statical"
],
]
],
[
"name" => "breadCrumb.specifications",
"route" => "specifications.categories",
"prefix" => "specifications",
"type" => "statical",
"children" => [
[
"name" => "breadCrumb.specificationsList",
"route" => "specifications.categories.list",
"prefix" => "categories",
"type" => "dynamic",
"field" => "id"
],
[
"name" => "breadCrumb.devicesView",
"route" => "specifications.categories.device",
"prefix" => "categories",
"type" => "dynamic",
"field" => "id",
],
[
"name" => "breadCrumb.partDescription",
"route" => "specifications.categories.device.part",
"prefix" => "categories",
"type" => "dynamic",
"field" => "id"
],
[
"name" => "breadCrumb.specificationsList",
"route" => "specifications.categories.devices",
"prefix" => "categories",
"type" => "static",
],
]
],
[
"name" => "breadCrumb.orders",
"route" => "orders.index",
"prefix" => "orders",
"type" => "statical",
"children" => [
[
"name" => "breadCrumb.ordersCreate",
"route" => "orders.cart",
"prefix" => "orders",
"type" => "statical"
],
[
"name" => "breadCrumb.ordersEdit",
"route" => "orders.edit",
"prefix" => "orders",
"type" => "dynamic",
"field" => "id"
],
[
"name" => "breadCrumb.ordersShow",
"route" => "orders.show",
"prefix" => "orders",
"type" => "dynamic",
"field" => "id"
],
[
"name" => "breadCrumb.repairsCreate",
"route" => "repairs.create",
"prefix" => "repairs",
"type" => "dynamic",
"field" => "id"
],
]
],
[
"name" => "breadCrumb.repairs",
"route" => "repairs.index",
"prefix" => "repairs",
"type" => "statical",
"children" => [
[
"name" => "breadCrumb.repairsEdit",
"route" => "repairs.edit",
"prefix" => "repairs",
"type" => "dynamic",
"field" => "id"
],
[
"name" => "breadCrumb.repairsShow",
"route" => "repairs.show",
"prefix" => "repairs",
"type" => "dynamic",
"field" => "id"
],
[
"name" => "breadCrumb.reporting",
"route" => "repairs.reporting",
"prefix" => "repairs",
"type" => "statical"
]
]
],
[
"name" => "breadCrumb.address",
"route" => "address.index",
"prefix" => "address",
"type" => "statical",
"children" => [
[
"name" => "breadCrumb.addressCreate",
"route" => "address.create",
"prefix" => "address",
"type" => "statical",
],
[
"name" => "breadCrumb.addressEdit",
"route" => "address.edit",
"prefix" => "address",
"type" => "dynamic",
"field" => "id"
],
[
"name" => "breadCrumb.addressShow",
"route" => "address.show",
"prefix" => "address",
"type" => "dynamic",
"field" => "id"
]
]
],
[
"name" => "breadCrumb.shipment",
"route" => "shipment.index",
"prefix" => "shipment",
"type" => "statical",
"children" => [
[
"name" => "breadCrumb.shipmentCreate",
"route" => "shipment.create",
"prefix" => "shipment",
"type" => "statical",
],
[
"name" => "breadCrumb.shipmentShow",
"route" => "shipment.show",
"prefix" => "shipment",
"type" => "dynamic",
"field" => "id"
]
]
],
[
"name" => "breadCrumb.acttc",
"route" => "acttc.index",
"prefix" => "acttc",
"type" => "statical",
"children" => [
[
"name" => "breadCrumb.acttcCreate",
"route" => "acttc.create",
"prefix" => "acttc",
"type" => "dynamic",
"field" => "id"
],
[
"name" => "breadCrumb.acttcShow",
"route" => "acttc.show",
"prefix" => "acttc",
"type" => "dynamic",
"field" => "id"
],
[
"name" => "breadCrumb.acttcEdit",
"route" => "acttc.edit",
"prefix" => "acttc",
"type" => "dynamic",
"field" => "id"
]
]
],
[
"name" => "breadCrumb.errors",
"route" => "errors.index",
"prefix" => "errors",
"type" => "statical",
"children" => [
[
"name" => "breadCrumb.errorsImport",
"route" => "errors.import.form",
"prefix" => "errors",
"type" => "statical",
]
]
],
[
"name" => "breadCrumb.movement",
"route" => "movement.index",
"prefix" => "movement",
"type" => "statical",
],
[
"name" => "breadCrumb.reconciliation",
"route" => "reconciliation.index",
"prefix" => "reconciliation",
"type" => "statical",
],
];
}
}