定制 wamesk/laravel-nova-price-field 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

wamesk/laravel-nova-price-field

最新稳定版本:1.3.0

Composer 安装命令:

composer require wamesk/laravel-nova-price-field

包简介

A Laravel Nova price field with moneyphp/money library.

README 文档

README

Installation

composer install wamesk/laravel-nova-price-field

Usage

Basic usage

Shows single input for price, when viewing on detail or index page, shows price with currency suffix symbol.

use Wame\LaravelNovaPriceField\Fields\Price;
....
Price::make('price'),

Showing total price

When you have quantity field (or something similar) you can show total price that dynamically calculates total price multiplying price with quantity.

use Wame\LaravelNovaPriceField\Fields\Price;
....
Price::make('price')
    ->asTotal(),

Usage should be only for viewing (detail and index page).

Multiple fields on form

This adds price without tax and tax input. Includes automatic calculation. Saves only price with tax.

use Wame\LaravelNovaPriceField\Fields\Price;
....
Price::make()
    ->withAllFieldOnForm()

If you want to save other fields you can set database column names so it can save multiple values.

use Wame\LaravelNovaPriceField\Fields\Price;
....
Price::make()
    ->withAllFieldOnForm(withoutTaxColumn: 'price_without_tax', taxColumn: 'tax')

Now it will save values to corresponding columns.

Using price inputs without tax input

You can hide tax input, but the calculation is not turned off. Adding ->setTax() method is recommended.

use Wame\LaravelNovaPriceField\Fields\Price;
....
Price::make()
    ->withAllFieldOnForm()
    ->hideTaxFormField()
    ->setTax(23)

Using predefined tax options

You can add taxFieldAsSelect() method to change number tax input to select with options.

use Wame\LaravelNovaPriceField\Fields\Price;
....
Price::make()
    ->withAllFieldOnForm()
    ->taxFieldAsSelect([
        10 => [
            'name' => 'Reduced tax (10%)',
        ],
        23 => [
            'name' => 'Standard tax (23%)',
        ],
    ])

You have option to save which option was selected by adding id to object and column name as 2nd parameter ot method.

use Wame\LaravelNovaPriceField\Fields\Price;
....
Price::make()
    ->withAllFieldOnForm()
    ->taxFieldAsSelect([
        10 => [
            'id' => 'reduced',
            'name' => 'Reduced tax (10%)',
        ],
        23 => [
            'id' => 'standard',
            'name' => 'Standard tax (23%)',
        ],
    ], 'vat_rate_type')

You have option to change save value to not be ID of option by the value (key of select) by adding true to 3rd parameter ($saveAsValue).

use Wame\LaravelNovaPriceField\Fields\Price;
....
Price::make()
    ->withAllFieldOnForm()
    ->taxFieldAsSelect([
        10 => [
            'id' => 'reduced',
            'name' => 'Reduced tax (10%)',
        ],
        23 => [
            'id' => 'standard',
            'name' => 'Standard tax (23%)',
        ],
    ], 'vat_rate_type', true)

统计信息

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

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-11-14