evanrthompson/nova-ratings 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

evanrthompson/nova-ratings

最新稳定版本:v1.0.0

Composer 安装命令:

composer require evanrthompson/nova-ratings

包简介

A star rating field for Laravel Nova with half-star ratings, custom icons, and color customization.

README 文档

README

A star rating field for Laravel Nova 5 with half-star ratings, custom icons, and color customization.

Requirements

  • PHP 8.3+
  • Laravel Nova 5.0+

Installation

composer require evanrthompson/nova-ratings

Usage

Add the field to your Nova resource:

use Evanrthompson\NovaRatings\NovaRatings;

public function fields(NovaRequest $request): array
{
    return [
        NovaRatings::make('Rating'),
    ];
}

Options

outOf(int $outOf)

Set the maximum rating scale. Default: 5.

NovaRatings::make('Rating')->outOf(10)

clearable()

Show a clear button that resets the rating to 0.

NovaRatings::make('Rating')->clearable()

allowHalf()

Enable half-star increments. Clicking the left half of an icon sets a .5 value, the right half sets a whole value.

NovaRatings::make('Rating')->allowHalf()

color(string $color)

Set the filled icon color using any CSS color value.

NovaRatings::make('Rating')->color('#f59e0b')

svg(string $path)

Use a custom SVG file instead of the default star. The SVG file is read at render time and should use currentColor for its fill to work with color().

NovaRatings::make('Rating')->svg(public_path('icons/heart.svg'))

emoji(string $emoji)

Use an emoji character instead of stars.

NovaRatings::make('Rating')->emoji('🔥')

Note: svg() and emoji() are mutually exclusive. If both are called, the last one wins.

Database

Ratings are always stored as a decimal between 0 and 1 (percentage of the maximum scale). Use a decimal column:

$table->decimal('rating', 3, 2)->default(0);

The field automatically converts between the stored percentage and the visual scale. For example, a rating of 3.5 out of 5 is stored as 0.70.

Configuration Example

A real-world resource using multiple rating fields with different configurations:

use Evanrthompson\NovaRatings\NovaRatings;

public function fields(NovaRequest $request): array
{
    return [
        NovaRatings::make('Rating')
            ->outOf(5)
            ->clearable()
            ->allowHalf()
            ->sortable()
            ->help('Overall recipe rating'),

        NovaRatings::make('Flavor')
            ->outOf(5)
            ->allowHalf()
            ->svg(public_path('icons/heart.svg'))
            ->color('#ef4444'),

        NovaRatings::make('Spice Level', 'spice_level')
            ->outOf(5)
            ->allowHalf()
            ->emoji('🌶️'),

        NovaRatings::make('Difficulty')
            ->outOf(3)
            ->emoji('🔪'),
    ];
}

Nova Compatibility

The field works with Nova's built-in readonly(), help(), sortable(), and rules() methods.

License

MIT

统计信息

  • 总下载量: 0
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 7
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: Vue

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-04-05

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固