Ratings let you gather user feedback on how well your product is received. You can easily integrate a rating system directly into your Filament tables!
We have a Product model, which we show in the table, and a Review model, where we save the star rating and review comments.
We use the mokhosh/filament-rating Filament plugin to add a star rating.
The table can be found in ProductResource. First, to show the number of reviews, we modify the query to load the number of reviews relationships. Then, we add another select to get users' ratings for the product.
app/Filament/Resources/Products/Tables/ProductsTable.php:
use App\Models\Review;use App\Models\Product;use Illuminate\Support\Str;use Illuminate\Database\Eloquent\Builder;use Filament\Tables\Table;use Filament\Tables\Columns\TextColumn;use Filament\Tables\Columns\ViewColumn; public static function configure(Table $table): Table{ return $table ->modifyQueryUsing(function (Builder $query) { return $query->withCount('reviews')// ...
Next, we will: