@php $schema = [ '@context' => 'https://schema.org', '@type' => 'Product', 'name' => $data->name, 'image' => [ asset($data->avatar_path), ], 'description' => strip_tags($data->description2), 'sku' => $data->sku, 'brand' => [ '@type' => 'Brand', 'name' => $data->category->name ?? 'Danh mục sản phẩm', ], 'offers' => [ '@type' => 'Offer', 'url' => url($data->slug_full), 'priceCurrency' => 'VND', 'price' => (int) $data->price, 'priceValidUntil' => now()->addYear()->format('Y-m-d'), 'availability' => 'https://schema.org/InStock', 'itemCondition' => 'https://schema.org/NewCondition', ], ]; // AggregateRating if (!empty($data->comments_count)) { $schema['aggregateRating'] = [ '@type' => 'AggregateRating', 'ratingValue' => round($data->rating ?? 5, 1), 'reviewCount' => (int) $data->comments_count, 'bestRating' => 5, 'worstRating' => 1, ]; } // Reviews if (!empty($data->comments) && $data->comments->count()) { foreach ($data->comments as $comment) { $schema['review'][] = [ '@type' => 'Review', 'author' => [ '@type' => 'Person', 'name' => $comment->name ?? 'Khách hàng', ], 'datePublished' => optional($comment->created_at)->format('Y-m-d'), 'reviewBody' => strip_tags($comment->content), 'reviewRating' => [ '@type' => 'Rating', 'ratingValue' => (int) ($comment->rating ?? 5), 'bestRating' => 5, 'worstRating' => 1, ], ]; } } @endphp