Star and Half Star Rating in Laravel



PHP Snippet 1:

.................
@for($i=0;$i<5;$i++)

  <?php
    $thisRating = product->ratings->avg('rating')
    if(floor($thisRating) != $thisRating) {
      $hasHalfVal = 1;
    } else {
      $hasHalfVal = 0;
    }
  ?>

   @if($thisRating > $i && $hasHalfVal == 0)
     <span class="icon-ratings"><i class="icon-rating icon-rating-x"></i></span>
   @else if($thisRating > $i && $hasHalfVal == 1) 
     <span class="icon-ratings"><i class="icon-rating icon-rating-half"></i></span>
   @else
     <span class="icon-ratings"><i class="icon-rating icon-rating-o"></i></span>
   @endif

 .................

PHP Snippet 2:

@for ($i = 1; $i <= 5; $i++)
    @if($product->ratings->avg('rating') < $i)
        @if (round($product->ratings->avg('rating')) == $i)


            <li class="list-inline-item me-0 small"><i
                    class="fas fa-star-half-alt text-warning"></i></li>
            @continue
        @endif
        <li class="list-inline-item me-0 small"><i
                class="far fa-star text-warning"></i></li>
        @continue
    @endif
    <li class="list-inline-item me-0 small"><i
            class="fas fa-star text-warning"></i></li>
@endfor