Ratings help your product collect information on how well things are received by users. And it is completely possible to build a rating system into the table!
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/ProductResource.php:
use Illuminate\Database\Eloquent\Builder; public static function table(Table $table): Table{ return $table ->modifyQueryUsing(function (Builder $query) { return $query->withCount('reviews') // ...