This is an improved fork of the StarRatingBundle from blackknight467 and brokoskokoli modified for support of Symfony 7!

Using Composer
Install package using Composer:
composer require boruta/star-rating-bundle
Enable the bundle in your project (this can be done automatically):
<?php
// config/bundles.php
return [
// ...
Boruta\StarRatingBundle\StarRatingBundle::class => ['all' => true],
];
Add the Twig config into config/packages/twig.yaml:
twig:
paths:
'%kernel.project_dir%/vendor/boruta/star-rating-bundle/Resources/views': BorutaStarRatingBundle
Add the CSS in your page head:
<link rel="stylesheet" type="text/css" href="{{ asset('bundles/starrating/css/rating.css') }}" />
Add the rating script to your page head:
<script src="{{ asset('bundles/starrating/js/rating.js') }}"></script>
and also JQuery if you don't use it already:
<script src="https//ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
Install Font Awesome (i.e. using NPM).
<?php
// ...
$builder->add('rating', StarRatingType::class, [
'label' => 'Rating'
]);
// ...
or for a custom rating scale:
<?php
// ...
$builder->add('rating', StarRatingType::class, [
//...
'stars' => 4,
//...
]);
// ...
{{ someInteger|rating }}
or if you are not using a 5 stars scale
{{ someInteger|rating(4) }}
if you want to use the font awesome icon sizes
{{ someInteger|rating(5, "fa-3x") }}
If you want the smallest size use "fa-norm" (in font awesome, this would be the same as not providing a size class); providing no size argument sets the font size to 25px which is somewhere in between "fa-lg" and "fa-2x". To customize the size, feel free to override the css.
This bundle is under the MIT license. See the complete license in the bundle: LICENSE
How can I help you explore Laravel packages today?