abdukhaligov/nova-rating-field

为 Laravel Nova 添加起始评分字段

该软件包的官方存储库似乎已消失,因此该软件包已被冻结。

安装量: 1,641

依赖者: 0

建议者: 0

安全: 0

星级: 0

关注者: 0

分支: 19

语言:Vue


README

这是一个用于在 Laravel Nova 应用中使用的 星级评分字段

使用 vue-star-rating

Latest Version on Packagist Total Downloads

players-index.png
players-edit.png

安装

您可以通过 composer 在使用 Nova 的 Laravel 应用中安装此软件包

composer require nikaia/nova-rating-field

接下来,您可以在 Nova 资源中使用 Nikaia\Rating\Rating 字段。

使用

public function fields(Request $request)
{
    return [
        // ...

        Rating::make('Rating')->min(0)->max(5)->increment(0.5)->hideFromIndex(),
        
        // Defining a custom style for the index page.
        Rating::make('Rating')->min(0)->max(5)->increment(0.5)->hideRating()
            ->withStyles([
                'star-size' => 15,
                'rounded-corners' => true,
            ])->onlyOnIndex()->sortable(),

        // ...    
        
    ];
}

定义属性

public function fields(Request $request)
{
    Rating::make('Rating')
    
        // Miniumum rating (default: 0)
        ->min(0) 
        
        // Maximum rating (default: 5)
        // This is how the component knows how many stars it should display.
        ->max(5)
        
        // Incremet (default: 1)
        // Can be float. The underlying eloquent colum must be defined as float in that case.
        // ie. 0.5 for half stars or 0.01 for fluid stars.
        ->increment(0.5)
        
        // Show rating value next to the stars
        ->hideRating()
        
}

自定义样式

您可以使用 withStyles 方法来设置组件样式。选项会被传递到底层的 vue 组件样式属性

默认值是

public function fields(Request $request)
{
    Rating::make('Rating')
        ->withStyles([
            'star-size' => 30,
            'active-color' => 'var(--primary)', // Primary nova theme color.
            'inactive-color' => '#d8d8d8',
            'border-color' => 'var(--60)',
            'border-width' => 0,
            'padding' => 10,
            'rounded-corners' => false,
            'inline' => false,
            'glow' => 0,
            'glow-color' => '#fff',
            'text-class' => 'inline-block text-80 h-9 pt-2',
        ]);
}