diff --git a/app/Http/Controllers/Fo/ProductController.php b/app/Http/Controllers/Fo/ProductController.php index 9ff5fe89..8cbed485 100644 --- a/app/Http/Controllers/Fo/ProductController.php +++ b/app/Http/Controllers/Fo/ProductController.php @@ -79,7 +79,7 @@ class ProductController extends Controller public function show(string $slug): \Illuminate\Contracts\View\View { /** @var \App\Models\Product|null $productModel Current product model */ - $productModel = Product::query()->where('slug', $slug)->first(); + $productModel = Product::query()->where([['slug', $slug], ['published', true]])->first(); if (is_null($productModel)) { abort(404); } diff --git a/app/Http/Controllers/Fo/RecipeController.php b/app/Http/Controllers/Fo/RecipeController.php index e3783767..13b39285 100644 --- a/app/Http/Controllers/Fo/RecipeController.php +++ b/app/Http/Controllers/Fo/RecipeController.php @@ -75,7 +75,7 @@ class RecipeController extends Controller public function show(string $slug): \Illuminate\Contracts\View\View { /** @var \App\Models\Recipe|null $recipeModel Current recipe model */ - $recipeModel = Recipe::query()->where('slug', $slug)->with([ + $recipeModel = Recipe::query()->where([['slug', $slug], ['published', true]])->with([ 'products.meat', 'products.submeat', 'products.approach' @@ -87,9 +87,10 @@ class RecipeController extends Controller $staticPageModel = StaticPage::getCachedStaticPage(StaticPageType::recipe); return view('fo.pages.recipes.show', [ - 'recipeModel' => $recipeModel, - 'recipeModels' => $this->getRecipesFiltered($recipeModel), - 'staticPageModel' => $staticPageModel, + 'recipeModel' => $recipeModel, + 'recipeModels' => $this->getRecipesFiltered($recipeModel), + 'associatedProductModels' => $recipeModel->products->where('published', true), + 'staticPageModel' => $staticPageModel, ]); } diff --git a/app/Models/Product.php b/app/Models/Product.php index ffa95fe0..054228bd 100644 --- a/app/Models/Product.php +++ b/app/Models/Product.php @@ -293,7 +293,7 @@ class Product extends Model implements SeoInterface, Sitemapable, SchemaOrgInter // Recipes associated. if ($model->recipes->count() && !$asReference) { $schema->subjectOf($model->recipes->where('published', true)->map(function (Recipe $recipe) { - return $recipe->toSchemaOrg(); + return $recipe->toSchemaOrg(true); })->toArray()); } @@ -318,7 +318,7 @@ class Product extends Model implements SeoInterface, Sitemapable, SchemaOrgInter } else { array_push($categories, $model->subrange->toSchemaOrg()); } - if ($model->load('claims')->meat_id) { + if ($model->meat_id) { array_push($categories, $model->meat->toSchemaOrg()); } else { array_push($categories, $model->submeat->toSchemaOrg()); diff --git a/app/Models/Recipe.php b/app/Models/Recipe.php index 004050b0..ecae9be2 100644 --- a/app/Models/Recipe.php +++ b/app/Models/Recipe.php @@ -327,7 +327,7 @@ class Recipe extends Model implements SeoInterface, Sitemapable, SchemaOrgInterf $schema->recipeIngredient($ingredientsList); // Products associated. - if (!$asReference) { + if ($model->products->count() && !$asReference) { $linkedProducts = $model->products->map(function (Product $product) { return $product->toSchemaOrg(true); })->toArray(); diff --git a/resources/views/fo/pages/recipes/show.blade.php b/resources/views/fo/pages/recipes/show.blade.php index 6c7b3b85..a49aacd0 100644 --- a/resources/views/fo/pages/recipes/show.blade.php +++ b/resources/views/fo/pages/recipes/show.blade.php @@ -133,18 +133,20 @@

-
-
-

{{ str(__('réalisé avec'))->upper() }}

-
- @foreach ($recipeModel->products as $productModel) -
- @include('fo.partials.product-card-tiny', [ - 'productModel' => $productModel, - ]) + @if ($associatedProductModels->count()) +
+
+

{{ str(__('réalisé avec'))->upper() }}

- @endforeach -
+ @foreach ($associatedProductModels as $productModel) +
+ @include('fo.partials.product-card-tiny', [ + 'productModel' => $productModel, + ]) +
+ @endforeach +
+ @endif

{{ str(__('les ingrédients'))->upper() }}

@@ -167,17 +169,17 @@
{{-- RECIPES --}} - @if ($recipeModels->isNotEmpty()) + @if ($recipeModels->isNotEmpty() && $associatedProductModels->count()) @include('fo.partials.cards-slider', [ 'id' => 'recipe', 'title' => $staticPageModel->data['recipes_title']['value'], 'text' => $staticPageModel->data['text']['value'], 'models' => $recipeModels, - 'btnRouteName' => $recipeModel->products->first()->meat - ? route('fo.recipes.search.meat', $recipeModel->products->first()->meat->slug) + 'btnRouteName' => $associatedProductModels->first()->meat + ? route('fo.recipes.search.meat', $associatedProductModels->first()->meat->slug) : route('fo.recipes.search.submeat', [ - 'model_slug' => $recipeModel->products->first()->submeat->first()->meat->slug, - 'child_slug' => $recipeModel->products->first()->submeat->slug, + 'model_slug' => $associatedProductModels->first()->submeat->first()->meat->slug, + 'child_slug' => $associatedProductModels->first()->submeat->slug, ]), 'btnRouteTitle' => 'nos recettes', ])