eom-plus/nova-rating-field
A Laravel Nova field that adds interactive star ratings to your resources. Let users set and display rating values through a customizable star widget, with configurable max stars, read-only display, and smooth integration across Nova forms, detail, and index views.
Install via Composer alongside a Laravel Nova 4 app:
composer require eom-plus/nova-rating-field
No service provider registration or publishing is required for a standard Nova 4 install. The field is used like any other Nova field inside a resource’s fields() method:
use EomPlus\NovaRatingField\Rating;
public function fields(NovaRequest $request)
{
return [
Rating::make('Rating')
->max(5)
->min(0)
->step(1),
];
}
Where to look first:
src/ directory for the field class namespace and available fluent methods.resources/js/ for the Vue component, to confirm props such as max, min, step, and any color/icon options.First use case: add a simple 5-star rating to an existing model. You need a numeric column already in the database:
Schema::table('products', function (Blueprint $table) {
$table->unsignedTinyInteger('rating')->default(0)->after('name');
});
Then cast it in the model ('rating' => 'integer') and add Rating::make('Rating')->max(5) to the Nova resource. This gives you an interactive star widget on the detail and update forms and a sensible display on index.
Basic form field with validation. The field is a frontend widget; server-side validation is still yours:
Rating::make('Rating')
->max(5)
->rules('required', 'integer', 'min:0', 'max:5')
->sortable(),
Because Nova passes rules through to the underlying request, keep the field’s max() and your validation max: in sync — they are independent settings.
Half-star / decimal ratings. If the Vue component supports step(0.5), store the value in a decimal(3,1) column and cast it accordingly:
$table->decimal('rating', 3, 1)->default(0);
// Model
protected $casts = ['rating' => 'float'];
Rating::make('Rating')->min(0)->max(5)->step(0.5),
If step is not exposed by the package version you have, fall back to integer stars or a plain Number field.
Index and detail display. Typical Nova fields support ->onlyOnIndex(), ->hideFromIndex(), and ->readonly(). Use read-only mode for audit views where the rating is derived:
Rating::make('Average Rating', 'average_rating')
->readonly()
->onlyOnDetail(),
Sorting. If the field exposes ->sortable(), it sorts by the underlying column. Confirm the column name matches the field attribute when you use a label/attribute split (Rating::make('Score', 'rating') sorts on rating).
Grouping with other fields. A common pattern is to pair the rating with a text justification or a reviewer field, and to use ->help() for tooltips:
Rating::make('Rating')->max(5)->help('1 = poor, 5 = excellent'),
Textarea::make('Review Notes')->alwaysShow(),
Dashboards and metrics. A rating field is not a metric card; for aggregate averages use Nova metrics with a ->avg('rating') calculation rather than trying to reuse the field on a dashboard.
composer.json. Read the Vue component source if a prop does not behave as expected."4") in JSON responses and inconsistent comparisons.nullable ratings. A nullable rating column plus a star widget can render awkwardly when the value is null. Decide whether null means “unrated” and either set a default of 0 or handle null display in your resource.->max(5) on the field configures the widget, not the request. Always add rules() or a FormRequest to prevent out-of-range values arriving via the API.vendor/.nova-components/ and register your own field, rather than patching the vendor package.php artisan nova:publish / clear caches (php artisan optimize:clear). For JS issues, run npm run dev in the Nova directory or check the browser console for component registration errors — small Nova packages occasionally lag behind Nova’s asset pipeline changes.How can I help you explore Laravel packages today?