Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Star Rating Bundle Laravel Package

boruta/star-rating-bundle

View on GitHub
Deep Wiki
Context7

StarRatingBundle

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

Sample Output

alt tag

Installation

Step 1: Download the StarRatingBundle

Using Composer

Install package using Composer:

composer require boruta/star-rating-bundle

Step 2: Enable the bundle

Enable the bundle in your project (this can be done automatically):

<?php
// config/bundles.php

return [
    // ...
    Boruta\StarRatingBundle\StarRatingBundle::class => ['all' => true],
];

Step 3: Config Twig views

Add the Twig config into config/packages/twig.yaml:

twig:
    paths:
        '%kernel.project_dir%/vendor/boruta/star-rating-bundle/Resources/views': BorutaStarRatingBundle

Step 4: Add the CSS

Add the CSS in your page head:

<link rel="stylesheet" type="text/css" href="{{ asset('bundles/starrating/css/rating.css') }}" />

Step 5: Add the JS

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>

Step 6: Install Font Awesome

Install Font Awesome (i.e. using NPM).

Usage

In a Symfony Forms

<?php
    // ...
    $builder->add('rating', StarRatingType::class, [
    	'label' => 'Rating'
    ]);
    // ...

or for a custom rating scale:

<?php
    // ...
    $builder->add('rating', StarRatingType::class, [
    	//...
    	'stars' => 4,
    	//...
    ]);
    // ...

Display in a Twig template using the rating filter

{{ 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.

License

This bundle is under the MIT license. See the complete license in the bundle: LICENSE

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
terminal42/code-quality-tools
codifyo/ts-generator-bundle
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky
spatie/mailcoach-vapor