fix bugs and deletes unnecessary files
This commit is contained in:
@@ -11,31 +11,23 @@ use Illuminate\Support\Facades\Route;
|
||||
|
||||
class BreadcrumbService
|
||||
{
|
||||
public function generateBreadcrumbs(): ?array
|
||||
public function generateBreadcrumbs($routeN = null): ?array
|
||||
{
|
||||
$routeName = Route::currentRouteName();
|
||||
|
||||
$routeName = $routeN ?? Route::currentRouteName();
|
||||
|
||||
// Пытаемся найти index-версию маршрута
|
||||
$indexRouteName = $this->getIndexRouteName($routeName);
|
||||
|
||||
|
||||
if ($indexRouteName === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Используем index-версию, если она существует
|
||||
$finalRouteName = Route::has($indexRouteName) ? $indexRouteName : null;
|
||||
|
||||
if ($finalRouteName === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$finalRouteName = Route::has($indexRouteName) ? $indexRouteName : $routeName;
|
||||
|
||||
$path = $this->generatePath($finalRouteName);
|
||||
|
||||
// Если path null, возвращаем null
|
||||
if ($path === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$page = Cache::remember('page_' . $path, now()->addHours(1), function () use ($path) {
|
||||
return Page::where('path', $path)
|
||||
->with('section.pages.section', 'section.mainSection')
|
||||
@@ -53,21 +45,33 @@ class BreadcrumbService
|
||||
];
|
||||
}
|
||||
|
||||
private function generatePath(string $routeName): string
|
||||
private function generatePath(string $routeName): ?string
|
||||
{
|
||||
if ($routeName === 'page.view') {
|
||||
return request()->path();
|
||||
}
|
||||
$routeUrl = route($routeName);
|
||||
|
||||
return ltrim(parse_url($routeUrl, PHP_URL_PATH), '/');
|
||||
try {
|
||||
$route = Route::getRoutes()->getByName($routeName);
|
||||
|
||||
// Если у маршрута есть обязательные параметры без значений по умолчанию, возвращаем null
|
||||
if ($route && count($route->parameterNames()) > 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$routeUrl = route($routeName);
|
||||
return ltrim(parse_url($routeUrl, PHP_URL_PATH), '/');
|
||||
} catch (\Exception $e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private function getIndexRouteName(string $routeName = null): string|null
|
||||
private function getIndexRouteName(string $routeName = null): ?string
|
||||
{
|
||||
if ($routeName === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$parts = explode('.', $routeName);
|
||||
|
||||
// Если в маршруте нет точек или он уже заканчивается на index
|
||||
|
||||
Reference in New Issue
Block a user