micchelfb / laravel-nova-time-field
为Laravel Nova设计的HTML5时间字段。
2.0.0
2023-02-09 18:34 UTC
Requires
- php: ^7.3|^8.0
- laravel/nova: ^4.0
Requires (Dev)
- phpunit/phpunit: ^9.5.10
This package is auto-updated.
Last update: 2024-09-09 21:53:06 UTC
README
此包向Laravel Nova添加了一个基本HTML5时间字段。
要求
此包需要laravel/nova:~4.0。
安装
使用composer安装此包。
composer require michielfb/laravel-nova-time-field
用法
以下示例展示了如何创建一个时间字段,用户可以输入小时、分钟和秒。时间显示为"h:i A"格式(例如11:15 PM)。如果没有输入值,则显示值"n/a"。
use Michielfb\Time\Time; Time::make('Time') ->withSeconds() ->format('h:i A', 'n/a');
有关如何向资源添加字段的文档,请参阅Laravel Nova文档。
格式
使用format
方法自定义如何向用户显示日期。格式必须是一个PHP日期格式。
可以将默认值传递给format
方法。这将确定如果没有输入值,则显示给用户的值。
use Michielfb\Time\Time; Time::make('Time') ->format('h:i A', '-');
步骤
可以使用withSteps
方法配置步长属性。
<?php use Michielfb\Time\Time; Time::make('Time')->withSteps(1);
withSeconds
方法设置步长为1,允许用户输入秒。
<?php use Michielfb\Time\Time; Time::make('Time')->withSeconds();
withMilliseconds
方法设置步长为0.001,允许用户输入毫秒。
<?php use Michielfb\Time\Time; Time::make('Time')->withMilliseconds();