jeffersongoncalves / filament-review-rateable
Filament components (star rating field, column, entry and reviews relation manager) for codebyray/laravel-review-rateable
Package info
github.com/jeffersongoncalves/filament-review-rateable
pkg:composer/jeffersongoncalves/filament-review-rateable
Requires
- php: ^8.2
- codebyray/laravel-review-rateable: ^2.3
- filament/filament: ^5.0
- spatie/laravel-package-tools: ^1.16
Requires (Dev)
- larastan/larastan: ^2.0|^3.0
- laravel/pint: ^1.0
- orchestra/testbench: ^10.0|^11.0
- pestphp/pest: ^3.0|^4.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
Filament Review Rateable
Filament UI for codebyray/laravel-review-rateable: a star rating form field, a star rating table column and infolist entry, and a ready-made reviews relation manager to create, edit, approve and delete reviews of any reviewable model.
Compatibility
| Package Version | Filament Version |
|---|---|
| 1.x | 3.x |
| 2.x | 4.x |
| 3.x | 5.x |
Installation
You can install the package via composer:
composer require jeffersongoncalves/filament-review-rateable:"^3.0"
Set up the core package (config + migrations) if you haven't yet:
php artisan vendor:publish --provider="Codebyray\ReviewRateable\ReviewRateableServiceProvider" --tag=config php artisan vendor:publish --provider="Codebyray\ReviewRateable\ReviewRateableServiceProvider" --tag=migrations php artisan migrate
Add the ReviewRateable trait to the models that receive reviews:
use Codebyray\ReviewRateable\Traits\ReviewRateable; class Product extends Model { use ReviewRateable; }
The components need no CSS build step: stars are inline SVG.
Usage
Reviews relation manager
Add it to the resource of any reviewable model:
use JeffersonGoncalves\Filament\ReviewRateable\RelationManagers\ReviewsRelationManager; public static function getRelations(): array { return [ ReviewsRelationManager::class, ]; }
It lists the reviews with author, average stars, text, department, recommendation and an approval toggle, filters by approval and department, and creates/edits reviews through the core ReviewRateableContract service, showing one star input per rating key of the selected department (review-rateable.departments). New reviews are attributed to the authenticated user.
Rating column
Show the average rating of a reviewable record:
use JeffersonGoncalves\Filament\ReviewRateable\Tables\Columns\RatingColumn; RatingColumn::make('rating')->average('overall'); // one criterion RatingColumn::make('rating')->average(null); // every criterion combined RatingColumn::make('rating')->average('overall', department: 'sales');
Without average() the column renders any numeric state as stars, e.g. RatingColumn::make('ratings_avg_value').
Rating entry
Same API for infolists:
use JeffersonGoncalves\Filament\ReviewRateable\Infolists\Components\RatingEntry; RatingEntry::make('rating')->average('overall');
Rating input
A clickable star field for your own forms:
use JeffersonGoncalves\Filament\ReviewRateable\Forms\Components\RatingInput; RatingInput::make('ratings.overall') ->label('Overall') ->required();
Bounds default to review-rateable.min_rating_value / max_rating_value and can be overridden with ->minRating() / ->maxRating() (also available on the column and the entry). Values outside the range fail validation.
Plugin
Registering the plugin is optional; the components work standalone:
use JeffersonGoncalves\Filament\ReviewRateable\ReviewRateablePlugin; $panel->plugins([ ReviewRateablePlugin::make(), ]);
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Credits
License
The MIT License (MIT). Please see License File for more information.
