fix: 🐛 fix schema condition to prevents loop between recipe and product models

This commit is contained in:
Alexis Gousseau 2025-06-11 16:21:48 +02:00
parent 5e684c6c02
commit aac04b4ca5
2 changed files with 3 additions and 3 deletions

View file

@ -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());

View file

@ -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();