l3aro/rating-star-for-filament
Add a star-rating field to Filament forms and tables with an easy-to-use UI. Display and edit ratings using customizable stars and sensible defaults, making it quick to collect feedback and show score values inside your admin panel.
Installation
composer require l3aro/rating-star-for-filament
Publish the package assets (if needed):
php artisan vendor:publish --provider="L3aro\RatingStarForFilament\RatingStarForFilamentServiceProvider" --tag="rating-star-assets"
Basic Usage Add the rating field to a Filament form/resource:
use L3aro\RatingStarForFilament\Fields\RatingStar;
RatingStar::make('rating')
->required()
->max(5)
->default(3),
First Use Case
Integrate into a Filament Resource or Page:
public static function form(Form $form): Form
{
return $form
->schema([
RatingStar::make('user_rating')
->columns(5)
->max(5),
]);
}
Dynamic Rating Ranges
Use max() and min() to control allowed values:
RatingStar::make('service_rating')
->max(10)
->min(1)
->default(5),
Conditional Display Hide/show based on logic:
RatingStar::make('review_rating')
->visible(fn ($record) => $record->isApproved()),
Validation Rules Extend Filament’s validation:
RatingStar::make('product_rating')
->rules(['required', 'integer', 'between:1,5']),
Database Integration
Ensure the column type matches (e.g., tinyint for 1–5 ratings):
Schema::table('products', function (Blueprint $table) {
$table->tinyInteger('rating')->default(0);
});
Custom Styling Override default assets via published CSS/JS:
// config/rating-star.php
'star_color' => '#FFD700',
'empty_color' => '#D3D3D3',
Column Type Mismatch
3.5) may fail if the DB column is tinyint.integer or decimal columns for half-star support.Asset Loading Conflicts
->extraAttributes(['class' => 'custom-rating']) and scope selectors.Half-Star Precision
max(5) assumes whole numbers.->max(10) and divide by 2 in logic:
$rating = $record->rating / 2;
Filament Version Compatibility
debug: true in config for JS errors.null, 0, and max values in forms.Custom Icons
Override SVG icons via ->starIcon() and ->emptyStarIcon():
RatingStar::make('rating')
->starIcon('heroicon-o-star')
->emptyStarIcon('heroicon-o-star'),
Event Hooks Listen for rating changes:
RatingStar::make('rating')
->afterStateUpdated(fn ($state, $set) => Log::info("Rating updated to: {$state}")),
Localization Translate labels/tooltips:
RatingStar::make('rating')
->label(__('filament-rating::rating.label'))
->helperText(__('filament-rating::rating.helper')),
How can I help you explore Laravel packages today?