PHP code example of packstub / filament-rating

1. Go to this page and download the library: Download packstub/filament-rating library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

packstub / filament-rating example snippets


use Packstub\FilamentRating\Components\Rating;

Rating::make('rating')
    ->

Rating::make('rating')
    ->stars(10)          // default 5
    ->allowZero()        // adds a "no stars" button that stores 0
    ->allowHalf()        // 0.5 steps: the left half of a star picks the half value
    ->clearable()        // click the selected star again, press Delete, or use the × button
    ->size('lg')         // xs, sm, md (default), lg, xl, 2xl, or an IconSize
    ->color('warning')   // default primary
    ->readOnly();

use Packstub\FilamentRating\Columns\RatingColumn;

RatingColumn::make('rating')
    ->sortable()
    ->searchable();

RatingColumn::make('reviews_avg_rating')
    ->avg('reviews', 'rating')
    ->showValue()                                                        // "4.3"
    ->precision(1)                                                       // max decimals, trailing zeros dropped
    ->showCount(fn (Product $record): int => $record->reviews_count)     // "(128)"
    ->placeholder('No reviews yet')
    ->tooltip(fn ($state): string => "Average of {$state}");

Rating::make('rating')
    ->labels([
        1 => 'Poor',
        2 => 'Fair',
        3 => 'Good',
        4 => 'Very good',
        5 => 'Excellent',
    ]);

Rating::make('rating')
    ->colors([
        1 => 'danger',   // 1 and 2
        3 => 'warning',  // 3
        4 => 'success',  // 4 and 5
    ]);

use Packstub\FilamentRating\Columns\RatingInputColumn;

RatingInputColumn::make('rating')
    ->clearable()
    ->disabled(fn (Review $record): bool => auth()->user()->cannot('update', $record))
    ->afterStateUpdated(fn (Review $record, ?int $state) => $record->touch());

use Packstub\FilamentRating\Filters\RatingFilter;

RatingFilter::make('rating');                    // 5 stars, 4 stars & up, … 1 star & up
RatingFilter::make('rating')->stars(10);
RatingFilter::make('rating')->exact();           // 5 stars, 4 stars, …

use Packstub\FilamentRating\Summarizers\RatingAverage;

RatingColumn::make('rating')
    ->stars(10)
    ->color('amber')
    ->summarize(RatingAverage::make());

use Packstub\FilamentRating\Summarizers\RatingDistribution;

RatingColumn::make('rating')
    ->summarize(RatingDistribution::make()); // ->percentages() for "40%" instead of counts

use Packstub\FilamentRating\Entries\RatingEntry;

RatingEntry::make('rating')
    ->showValue()
    ->size('lg');

use Filament\Support\Facades\FilamentIcon;
use Packstub\FilamentRating\RatingIcon;

FilamentIcon::register([
    RatingIcon::Star => 'heroicon-s-heart',
    RatingIcon::StarEmpty => 'heroicon-o-heart',
]);