2026-03-16 12:36:44 +01:00
|
|
|
<?php
|
|
|
|
|
|
2026-07-08 14:55:18 +02:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
2026-11-05 16:49:42 +01:00
|
|
|
use App\Dto\ProductDto;
|
|
|
|
|
use App\Dto\RecipeDto;
|
2026-03-16 12:36:44 +01:00
|
|
|
use Diglactic\Breadcrumbs\Breadcrumbs;
|
|
|
|
|
use Diglactic\Breadcrumbs\Generator;
|
2026-10-16 09:46:45 +02:00
|
|
|
use Illuminate\Support\Facades\Log;
|
2026-06-25 10:04:49 +02:00
|
|
|
use Illuminate\Support\Facades\Schema;
|
2026-04-07 16:21:09 +02:00
|
|
|
use Mcamara\LaravelLocalization\Facades\LaravelLocalization;
|
|
|
|
|
use Uwil\LaravelDynamicPages\Enums\PageStatusEnum;
|
2026-07-08 14:55:18 +02:00
|
|
|
use Uwil\LaravelDynamicPages\Helpers\RouteHelper;
|
|
|
|
|
use Uwil\LaravelDynamicPages\Models\DynamicPage;
|
2026-03-16 12:36:44 +01:00
|
|
|
|
2026-06-25 10:04:49 +02:00
|
|
|
// FIXME: This should be refactored, a work has to be done in coordination with the concerned package.
|
2026-07-08 14:55:18 +02:00
|
|
|
if (! Schema::hasTable((new DynamicPage())->getTable())) {
|
2026-06-25 10:04:49 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-07 16:21:09 +02:00
|
|
|
$currentLocale = app()->getLocale();
|
|
|
|
|
$supportedLocales = LaravelLocalization::getSupportedLanguagesKeys();
|
|
|
|
|
|
|
|
|
|
$pageHome = DynamicPage::getModelsCached()
|
|
|
|
|
->where('status', PageStatusEnum::published)
|
|
|
|
|
->where('isRoot', true)
|
|
|
|
|
->first();
|
|
|
|
|
DynamicPage::getModelsCached()->map(function (DynamicPage $dynamicPageModel) use ($supportedLocales, $pageHome) {
|
|
|
|
|
collect($supportedLocales)->map(function (string $locale) use ($dynamicPageModel, $pageHome) {
|
|
|
|
|
Breadcrumbs::for(
|
2026-07-08 14:55:18 +02:00
|
|
|
sprintf('front.dynamic-pages.%s.%s', $dynamicPageModel->id_key, $locale),
|
2026-04-07 16:21:09 +02:00
|
|
|
function (Generator $trail) use ($locale, $dynamicPageModel, $pageHome) {
|
2026-07-08 14:55:18 +02:00
|
|
|
if (! is_null($dynamicPageModel->page_id)) {
|
2026-04-07 16:21:09 +02:00
|
|
|
$trail->parent(sprintf(
|
2026-07-08 14:55:18 +02:00
|
|
|
'front.dynamic-pages.%s.%s',
|
2026-04-07 16:21:09 +02:00
|
|
|
$dynamicPageModel->parentPage->id_key,
|
|
|
|
|
$locale,
|
|
|
|
|
));
|
|
|
|
|
} elseif (isset($pageHome) && $dynamicPageModel->id_key !== $pageHome->id_key) {
|
2026-07-08 14:55:18 +02:00
|
|
|
$trail->parent(sprintf('front.dynamic-pages.%s.%s', $pageHome->id_key, $locale));
|
2026-04-07 16:21:09 +02:00
|
|
|
}
|
|
|
|
|
$trail->push(
|
|
|
|
|
$dynamicPageModel->title,
|
2026-07-08 14:55:18 +02:00
|
|
|
RouteHelper::routeNameChecker(sprintf('front.dynamic-pages.%s', $dynamicPageModel->id_key))
|
2026-04-07 16:21:09 +02:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Breadcrumbs::for('front.engage', function (Generator $trail) {
|
2026-04-08 13:59:30 +02:00
|
|
|
$currentLocale = app()->getLocale();
|
|
|
|
|
$pageHome = DynamicPage::getModelsCached()
|
2026-06-25 10:04:49 +02:00
|
|
|
->where('status', PageStatusEnum::published)
|
|
|
|
|
->where('isRoot', true)
|
|
|
|
|
->first();
|
2026-04-07 16:21:09 +02:00
|
|
|
|
2026-07-08 14:55:18 +02:00
|
|
|
$trail->parent(sprintf('front.dynamic-pages.%s.%s', $pageHome->id_key, $currentLocale));
|
2026-04-07 16:21:09 +02:00
|
|
|
$trail->push(
|
2026-08-07 14:46:51 +02:00
|
|
|
ucfirst(__('front.ovoteam_commit')),
|
2026-04-07 16:21:09 +02:00
|
|
|
route('front.engage')
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
2026-04-08 13:59:30 +02:00
|
|
|
Breadcrumbs::for('front.made-in-france', function (Generator $trail) use ($pageHome, $currentLocale) {
|
|
|
|
|
$currentLocale = app()->getLocale();
|
|
|
|
|
$pageHome = DynamicPage::getModelsCached()
|
2026-06-25 10:04:49 +02:00
|
|
|
->where('status', PageStatusEnum::published)
|
|
|
|
|
->where('isRoot', true)
|
|
|
|
|
->first();
|
2026-07-08 14:55:18 +02:00
|
|
|
$trail->parent(sprintf('front.dynamic-pages.%s.%s', $pageHome->id_key, $currentLocale));
|
2026-04-07 16:21:09 +02:00
|
|
|
$trail->push(
|
2026-08-07 14:46:51 +02:00
|
|
|
ucfirst(__('front.ovoteam_commit')),
|
2026-04-07 16:21:09 +02:00
|
|
|
route('front.engage')
|
|
|
|
|
);
|
|
|
|
|
$trail->push(
|
2026-07-08 14:55:18 +02:00
|
|
|
trans('front.made-in-france'),
|
2026-04-07 16:21:09 +02:00
|
|
|
route('front.made-in-france')
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
2026-04-08 13:59:30 +02:00
|
|
|
Breadcrumbs::for('front.expertise', function (Generator $trail) use ($currentLocale, $pageHome) {
|
2026-07-08 14:55:18 +02:00
|
|
|
$trail->parent(sprintf('front.dynamic-pages.%s.%s', $pageHome->id_key, $currentLocale));
|
2026-04-07 16:21:09 +02:00
|
|
|
$trail->push(
|
2026-08-07 14:46:51 +02:00
|
|
|
ucfirst(__('front.ovoteam_commit')),
|
2026-04-07 16:21:09 +02:00
|
|
|
route('front.engage')
|
|
|
|
|
);
|
|
|
|
|
$trail->push(
|
2026-07-08 14:55:18 +02:00
|
|
|
trans('front.expertise'),
|
2026-04-07 16:21:09 +02:00
|
|
|
route('front.expertise')
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
2026-04-08 13:59:30 +02:00
|
|
|
Breadcrumbs::for('front.gamme', function (Generator $trail) use ($pageHome, $currentLocale) {
|
2026-07-08 14:55:18 +02:00
|
|
|
$trail->parent(sprintf('front.dynamic-pages.%s.%s', $pageHome->id_key, $currentLocale));
|
2026-04-07 16:21:09 +02:00
|
|
|
$trail->push(
|
2026-08-07 14:46:51 +02:00
|
|
|
ucfirst(__('front.ovoteam_commit')),
|
2026-04-07 16:21:09 +02:00
|
|
|
route('front.engage')
|
|
|
|
|
);
|
2026-03-16 12:36:44 +01:00
|
|
|
$trail->push(
|
2026-07-08 14:55:18 +02:00
|
|
|
trans('front.gamme'),
|
2026-04-07 16:21:09 +02:00
|
|
|
route('front.gamme')
|
2026-03-16 12:36:44 +01:00
|
|
|
);
|
|
|
|
|
});
|
2026-04-15 09:31:43 +02:00
|
|
|
|
|
|
|
|
Breadcrumbs::for('front.contact-us', function (Generator $trail) use ($currentLocale, $pageHome) {
|
2026-07-08 14:55:18 +02:00
|
|
|
$trail->parent(sprintf('front.dynamic-pages.%s.%s', $pageHome->id_key, $currentLocale));
|
2026-04-15 09:31:43 +02:00
|
|
|
$trail->push(
|
2026-07-08 14:55:18 +02:00
|
|
|
trans('front.contactpage'),
|
2026-04-15 09:31:43 +02:00
|
|
|
route('front.contact-us')
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Breadcrumbs::for('front.search', function (Generator $trail) use ($currentLocale, $pageHome) {
|
2026-07-08 14:55:18 +02:00
|
|
|
$trail->parent(sprintf('front.dynamic-pages.%s.%s', $pageHome->id_key, $currentLocale));
|
2026-04-15 09:31:43 +02:00
|
|
|
$trail->push(
|
2026-07-08 14:55:18 +02:00
|
|
|
trans('front.search'),
|
2026-04-15 09:31:43 +02:00
|
|
|
route('front.search')
|
|
|
|
|
);
|
|
|
|
|
});
|
2026-07-08 14:55:18 +02:00
|
|
|
|
|
|
|
|
Breadcrumbs::for('front.products.index', function (Generator $trail) use ($pageHome, $currentLocale) {
|
|
|
|
|
$trail->parent(sprintf('front.dynamic-pages.%s.%s', $pageHome->id_key, $currentLocale));
|
|
|
|
|
$trail->push(
|
|
|
|
|
trans('front.titles.products'),
|
|
|
|
|
route('front.products.index')
|
|
|
|
|
);
|
|
|
|
|
});
|
2026-07-08 16:32:12 +02:00
|
|
|
Breadcrumbs::for('front.products.show', function (Generator $trail) use ($pageHome, $currentLocale) {
|
2026-11-05 16:49:42 +01:00
|
|
|
$product = request()->route('frontProduct');
|
2026-07-08 16:32:12 +02:00
|
|
|
|
2026-11-05 16:49:42 +01:00
|
|
|
if (! $product instanceof ProductDto) {
|
2026-10-16 09:46:45 +02:00
|
|
|
Log::warning('Product not found for breadcrumb generation.');
|
|
|
|
|
|
|
|
|
|
return;
|
2026-07-08 16:32:12 +02:00
|
|
|
}
|
|
|
|
|
|
2026-07-08 14:55:18 +02:00
|
|
|
$trail->parent(sprintf('front.dynamic-pages.%s.%s', $pageHome->id_key, $currentLocale));
|
|
|
|
|
$trail->push(
|
|
|
|
|
trans('front.titles.products'),
|
|
|
|
|
route('front.products.index')
|
|
|
|
|
);
|
|
|
|
|
$trail->push(
|
|
|
|
|
$product->name,
|
2026-11-05 16:49:42 +01:00
|
|
|
route('front.products.show', ['frontProduct' => $product->slug])
|
2026-07-08 14:55:18 +02:00
|
|
|
);
|
|
|
|
|
});
|
2026-07-13 12:29:10 +02:00
|
|
|
|
|
|
|
|
Breadcrumbs::for('front.recipes.index', function (Generator $trail) use ($pageHome, $currentLocale) {
|
|
|
|
|
$trail->parent(sprintf('front.dynamic-pages.%s.%s', $pageHome->id_key, $currentLocale));
|
|
|
|
|
$trail->push(
|
|
|
|
|
trans('front.titles.recipes'),
|
|
|
|
|
route('front.recipes.index')
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
Breadcrumbs::for('front.recipes.show', function (Generator $trail) use ($pageHome, $currentLocale) {
|
2026-11-05 16:49:42 +01:00
|
|
|
$recipe = request()->route('frontRecipe');
|
2026-07-13 12:29:10 +02:00
|
|
|
|
2026-11-05 16:49:42 +01:00
|
|
|
if (! $recipe instanceof RecipeDto) {
|
2026-10-16 09:46:45 +02:00
|
|
|
Log::warning('Recipe not found for breadcrumb generation.');
|
|
|
|
|
|
|
|
|
|
return;
|
2026-07-13 12:29:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$trail->parent(sprintf('front.dynamic-pages.%s.%s', $pageHome->id_key, $currentLocale));
|
|
|
|
|
$trail->push(
|
|
|
|
|
trans('front.titles.recipes'),
|
|
|
|
|
route('front.recipes.index')
|
|
|
|
|
);
|
|
|
|
|
$trail->push(
|
|
|
|
|
$recipe->name,
|
2026-11-05 16:49:42 +01:00
|
|
|
route('front.recipes.show', ['frontRecipe' => $recipe->slug])
|
2026-07-13 12:29:10 +02:00
|
|
|
);
|
|
|
|
|
});
|