承接 gabelbart/nova-improved-date-field 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

gabelbart/nova-improved-date-field

Composer 安装命令:

composer require gabelbart/nova-improved-date-field

包简介

A Laravel Nova field.

关键字:

README 文档

README

This package for Laravel Nova aims at improving the default date and datetime field. The problem with the original field, that it has very little options for customizing the date format.

The \Gabelbart\Laravel\Nova\Fields\Date\Date and \Gabelbart\Laravel\Nova\Fields\Date\DateTime fields provided by this package are derived from the original \Laravel\Nova\Fields\Date and \Laravel\Nova\Fields\DateTime fields. However, the Vue components got replaced with a more customizable version, that is still using the luxon package. This package can coexist with the native Date/Datetime fields of laravel Nova.

This package also provides an option to use flatpickr since some browsers have incomplete support for the type="datetime-local" input field. The flatpickr will only be enabled on Firefox-desktop (enableFirefoxFlatpickr) and Safari (enableSafariFlatpickr)

Requirements

  • php: ^8.0
  • laravel/nova: ^4.0

Usage

Installation

Install the package via Composer:

composer require gabelbart/nova-improved-date-field

Getting started

Just use it like the default Laravel Nova date(time)-fields. For customizing behavior and appearance see options below.

<?php

namespace App\Nova;

use Laravel\Nova\Fields\ID;
use Laravel\Nova\Http\Requests\NovaRequest;

use Gabelbart\Laravel\Nova\Fields\Date\DateTime;

class User extends Resource
{
    public static $model = \App\Models\User::class;
    public static $title = 'name';
    public static $search = ['id'];

    public function fields(NovaRequest $request): array
    {
        return [
            ID::make()->sortable(),

            DateTime::make('Email verified at'),
        ];
    }

    // snip...
}

Or just replace the imports of \Laravel\Nova\Fields\DateTime or \Laravel\Nova\Fields\Date with \Gabelbart\Laravel\Nova\Fields\Date\DateTime or \Gabelbart\Laravel\Nova\Fields\Date\Date.

Options

enableFirefoxFlatpickr(bool $flag = true)/enableSafariFlatpickr(bool $flag = true)

The Firefox/Safari implementation of the datetime-local field is incomplete with the desktop browser. For the date a picker is provided but the time has to be entered manually. This can confuse some users. Setting this option to true will enable flatpickr in the Firefox desktop browser.

\Gabelbart\Laravel\Nova\Fields\Date\DateTime::make('Created at')
  ->enableFirefoxFlatpickr()
  ->enableSafariFlatpickr();

If you need users to be able to clear the field use the nullable option for Laravel Nova's Fields. This wil enable a clear button within the flatpickr dialog.

intlDateFormatOptions(array $options)

Set the Intl.DateTimeFormat parameters for luxon's DateTime.toLocaleString method. In the original implementation of Novas Vue component these where hardcoded.

It is not possible to change the format of the picker input, this will always be the format defined by the browser!

\Gabelbart\Laravel\Nova\Fields\Date\DateTime::make('Created at')
  ->intlDateFormatOptions([
    'year' => 'numeric',
    'month' => '2-digit',
    'day' => '2-digit',
    'hour' => '2-digit',
    'minute' => '2-digit',
  ]);

See the MDN docs for a full list of possible options.

timezone(?string $timezone)

By default, the field will use the timezone configured via Nova. With this option you can change the timezone used to display the date. Call this option with null to revert the prior calls to timezone.

\Gabelbart\Laravel\Nova\Fields\Date\DateTime::make('Created at')
  ->timezone('Africa/Nairobi');

See a full list of timezones on timezonedb.com

showTimezone(bool $flag)

Show the timezone for the value. On index/detail this will set the timeZoneName for the Intl.DateTimeFormat. On forms this will show the name of the timezone behind the input.

!!! This option can conflict with intlDateFormatOptions:

  • If you set this to false but configured a timeZone option for intlDateFormatOptions, it will still display a timezone.
  • If you set this to true the timeZone option for intlDateFormatOptions will be overwritten with timezoneName

You can use these options to fine tune the visibility for index, detail and form

  • showTimezoneOnIndex
  • showTimezoneOnDetail
  • showTimezoneOnForms

timezoneName(string $name)

Change the display of the timezone. This will only have effect in combination with showTimezone(true). Possible values can be found at the MDN docs for Intl.DateTimeFormat.

You can use these options to fine tune the display for index, detail and form

  • timezoneNameOnIndex
  • timezoneNameOnDetail
  • timezoneNameOnForms

showDiff(bool $flag = true)

Show a diff created with luxon's DateTime.toRelative method. On forms this will show a diff behind the input, live-updating to the date set via the input.

You can use these options to control the diff-display for index, detail and form

  • showDiffOnIndex
  • showDiffOnDetail
  • showDiffOnForms

showDiffAsPrimaryInformation(bool $flag = true)

By default, the diff enabled via showDiff will be shown in parentheses behind the date. You can invert this behavior by setting this option. The diff will be shown as primary value and the date in parentheses behind it.

comment(?string $comment = null)

Sow a comment behind the value. This is especially useful if you changed the timezone so something else but the user/app timezone via the timezone option.

hideCommentFromIndex(bool $flag = true)

Prevent the comment from getting shown on index columns in order to save space.

Recommendations

This step is optional, but I'd suggest that you derive your own classes from \Gabelbart\Laravel\Nova\Fields\Date\DateTime and \Gabelbart\Laravel\Nova\Fields\Date\Date. This way you will be able to improve on consistency, maintainability and readability of your code!

In your custom classes you can predefine Constants for the formats you are aiming to use in your app like \App\Nova\DateTime::FORMAT_SHORT or \App\Nova\DateTime::FORMAT_LONG (see intlDateFormatOptions for details). You can also predefine sets of options you want to combine in methods to maintain the DRY principle.

Alternative:

Both \Gabelbart\Laravel\Nova\Fields\Date\DateTime and \Gabelbart\Laravel\Nova\Fields\Date\Date can be configured with global defaults. This can be done via the setDefaults and addDefaults static methods. Call these in your \App\Providers\NovaServiceProvider::boot method. The setDefaults method replaces all defaults already present, the addDefaults merges the already registered defaults with the ones passed as parameter. The Parameter is an array option => [value], for possible options see the 'Options' section below.

gabelbart/nova-improved-date-field 适用场景与选型建议

gabelbart/nova-improved-date-field 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 44.4k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2023 年 02 月 24 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「nova」 「laravel」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 gabelbart/nova-improved-date-field 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 gabelbart/nova-improved-date-field 我们能提供哪些服务?
定制开发 / 二次开发

基于 gabelbart/nova-improved-date-field 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-02-24