Fix sitemap generator config + Product filter routes

This commit is contained in:
Jérémy Munsch 2021-05-21 10:26:03 +02:00
parent 63a4362ae9
commit c00bd55f04
5 changed files with 39 additions and 25 deletions

View file

@ -10,6 +10,7 @@ use App\Models\Moments;
use App\Models\Products;
use App\Models\Ranges;
use App\Models\Recipes;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;
@ -25,7 +26,7 @@ class ProductsController extends Controller
return view('front.products.index', compact('productsSlides', 'ranges', 'meatTypes', 'ct'));
}
public function filter($slug)
public function filter(Model $model)
{
// On récupère les mêmes données qu'au dessus pour l'affichage
$productsSlides = ProductSliderPictures::where('status', 1)->orderBy('order', 'ASC')->get();
@ -42,27 +43,21 @@ class ProductsController extends Controller
switch ($type) {
case 'gamme':
$gamme = Ranges::where([['slug', $slug], ['status', 1]])->firstOrFail();
if (!$gamme) {
abort(404);
}
/** @var \App\Models\Ranges */
$gamme = $model;
$productsList = $gamme->products->where('status', 1)->sortBy('order');
$title = $gamme->name;
break;
case 'type-viande':
$meatType = MeatTypes::where([['slug', $slug], ['status', 1]])->firstOrFail();
if (!$meatType) {
abort(404);
}
/** @var \App\Models\MeatTypes */
$meatType = $model;
$productsList = $meatType->products->where('status', 1)->sortBy('order');
$title = $meatType->name;
$typeViande = true;
break;
case 'moment-consommations':
$consumptionTime = ConsumptionTimes::where([['slug', $slug], ['status', 1]])->firstOrFail();
if (!$ct) {
abort(404);
}
/** @var \App\Models\ConsumptionTimes */
$consumptionTime = $model;
$productsList = $consumptionTime->products->where('status', 1)->sortBy('order');
$title = $consumptionTime->name;
$momentConso = true;

View file

@ -64,13 +64,13 @@ class RefreshSiteMap implements ShouldQueue
'product' => [Products::class, 'slug']
],
'products.range' => [
'gammeSlug' => [Ranges::class, 'slug']
'slugRange' => [Ranges::class, 'slug']
],
'products.consumption-times' => [
'slugMoment' => [Moments::class, 'slug']
'slugConsumptionTime' => [Ranges::class, 'slug']
],
'products.meat-type' => [
'slugTypeViande' => [MeatTypes::class, 'slug']
'slugMeatType' => [MeatTypes::class, 'slug']
],
'kitchen-side.health-nutrition.balanced-menu.menu' => [
'type' => [BalancedMenuType::class, 'type']
@ -131,6 +131,16 @@ class RefreshSiteMap implements ShouldQueue
$pName = $pNames[$param->getPosition()];
}
if (config('app.debug')) {
dump(sprintf(
'Route nom : %s, Param [type: %s, nom: %s, binder: %s]',
$route->getName(),
$name ? $name->getName() : '',
$pName,
$this->hasRouteBinderParam($route, $pName) ? 'true' : 'false'
));
}
// If We have a custom binder for this route
if ($this->hasRouteBinderParam($route, $pName)) {
$hasModels = true;

View file

@ -59,6 +59,15 @@ class RouteServiceProvider extends ServiceProvider
Route::bind('moment', function ($value) {
return Moments::where('id', $value)->orWhere('slug', $value)->firstOrFail();
});
Route::bind('slugRange', function ($value) {
return Ranges::where('slug', $value)->where('status', true)->firstOrFail();
});
Route::bind('slugConsumptionTime', function ($value) {
return ConsumptionTimes::where('slug', $value)->where('status', true)->firstOrFail();
});
Route::bind('slugMeatType', function ($value) {
return MeatTypes::where('slug', $value)->where('status', true)->firstOrFail();
});
Route::bind('consumptiontime', function ($value) {
return ConsumptionTimes::where('id', $value)->orWhere('slug', $value)->firstOrFail();
});

View file

@ -45,25 +45,25 @@ Breadcrumbs::for('products.range', function (Generator $trail) {
$trail->parent('products.index');
$trail->push(__('Gammes'));
});
Breadcrumbs::for('products.range.show', function (Generator $trail, $gammeSlug) {
Breadcrumbs::for('products.range.show', function (Generator $trail, $slugRange) {
$trail->parent('products.range');
$trail->push(ucfirst($gammeSlug), route('products.range', compact('gammeSlug')));
$trail->push(ucfirst($slugRange), route('products.range', compact('slugRange')));
});
Breadcrumbs::for('products.meat-type', function (Generator $trail) {
$trail->parent('products.index');
$trail->push(__('Types de viandes'));
});
Breadcrumbs::for('products.meat-type.show', function (Generator $trail, $slugTypeViande) {
Breadcrumbs::for('products.meat-type.show', function (Generator $trail, $slugMeatType) {
$trail->parent('products.meat-type');
$trail->push(ucfirst($slugTypeViande), route('products.meat-type', compact('slugTypeViande')));
$trail->push(ucfirst($slugMeatType), route('products.meat-type', compact('slugMeatType')));
});
Breadcrumbs::for('products.consumption-times', function (Generator $trail) {
$trail->parent('products.index');
$trail->push(__('Moments de consommation'));
});
Breadcrumbs::for('products.consumption-times.show', function (Generator $trail, $slugMoment) {
Breadcrumbs::for('products.consumption-times.show', function (Generator $trail, $slugConsumptionTime) {
$trail->parent('products.consumption-times');
$trail->push(ucfirst($slugMoment), route('products.consumption-times', compact('slugMoment')));
$trail->push(ucfirst($slugConsumptionTime), route('products.consumption-times', compact('slugConsumptionTime')));
});
Breadcrumbs::for('products.departaimants', function (Generator $trail) {
$trail->parent('products.index');

View file

@ -171,9 +171,9 @@ Route::prefix('/produits')
->group(function () {
Route::get('/', [ProductsController::class, 'index'])->name('index');
Route::get('/departaimants', [ProductsController::class, 'departaimants'])->name('departaimants');
Route::get('/gamme/{gammeSlug}', [ProductsController::class, 'filter'])->name('range');
Route::get('/moment-consommations/{slugMoment}', [ProductsController::class, 'filter'])->name('consumption-times');
Route::get('/type-viande/{slugTypeViande}', [ProductsController::class, 'filter'])->name('meat-type');
Route::get('/gamme/{slugRange}', [ProductsController::class, 'filter'])->name('range');
Route::get('/moment-consommations/{slugConsumptionTime}', [ProductsController::class, 'filter'])->name('consumption-times');
Route::get('/type-viande/{slugMeatType}', [ProductsController::class, 'filter'])->name('meat-type');
});
Route::prefix('/produit')