Skip to content

Instantly share code, notes, and snippets.

@cvega93
Created February 23, 2018 23:10
Show Gist options
  • Save cvega93/d451421bb02d0d836c6765ccb9ebeba7 to your computer and use it in GitHub Desktop.
Save cvega93/d451421bb02d0d836c6765ccb9ebeba7 to your computer and use it in GitHub Desktop.
Loop rating stars with blade + Google Markup Microdata
//use Fontawesome
@for ($x = 1; $x <= $name->ratingAverage; $x++)
<i class="fa fa-star"></i>
@endfor
@if (strpos($name->ratingAverage, '.'))
<i class="fa fa-star-half-o"></i>
@php
$x++;
@endphp
@endif
@while ($x <= 5)
<i class="fa fa-star-o"></i>
@php
$x++;
@endphp
@endwhile
//Google Markup Microdata
<script type="application/ld+json">
{
"@context": "http://schema.org",
"@type": "Product",
"description": "{{$name->description}}",
"name": "{{$name->name}}",
"aggregateRating": {
"@type": "AggregateRating",
"ratingCount": "{{ $name->ratings->count() }}",
"ratingValue": "{{ $name->ratingAverage }}"
}
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment