wdelfuego/nova4-formattable-date 问题修复 & 功能扩展

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

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

wdelfuego/nova4-formattable-date

最新稳定版本:v1.0.2

Composer 安装命令:

composer require wdelfuego/nova4-formattable-date

包简介

Formattable DateTime fields for Laravel's Nova 4

README 文档

README

Version 1.0.2 is the final version of this package. If you are using Nova 4.2.4 or newer and want to keep using the withDateFormat helper or the custom filters introduced by this package, you should use the generic wdelfuego/nova-datetime package instead.

As of Nova 4.2.4, custom DateTime formatting is available natively in Nova.

This package reintroduces custom DateTime formatting to DateTime fields in Nova 4 resources and comes with a couple of custom filters to circumvent the issues described in this discussion.

Installation

Add the dependency to your project's composer.json:

composer require wdelfuego/nova4-formattable-date

Usage

The examples below assume that the Eloquent model used for the Nova resource has an attribute named 'attribute'.

Formatting

In your Nova resource's fields method, add a DateTime field as usual but add a call to withDateFormat to set the format you want to show on Index and Resource views:

    Fields\DateTime::make(__('Localized label'), 'attribute')
        ->withDateFormat('d-M-Y, H:i'),

This field will automatically be hidden from Nova's forms, so add another DateTime field without withDateFormat for the same attribute so your end users can edit the field on forms:

    Fields\DateTime::make(__('Localized label'), 'attribute')
        ->onlyOnForms(),

The Field with the custom date format can be made sortable as usual, but the filterable option doesn't work in combination with the custom date format, so if you want to allow end users to filter the Index view based on the formatted DateTime column, see the next section for adding the custom filters that come with this package.

Filtering

This package comes with 5 different filters:

  • DateFilter only shows items whose date match the filter value
  • DateFilterAfter only shows items whose date is later than the filter value
  • DateFilterAfterOrOn only shows items whose date is later than or on the same date as the filter value
  • DateFilterBefore only shows items whose date is earlier than the filter value
  • DateFilterBeforeOrOn only shows items whose date is earlier than or on the same date as the filter value

You can add a combination of these filters to the Nova resource to allow end users to define a date range.

For example:

    public function filters(NovaRequest $request)
    {
        return [
            new DateFilterAfter(__('After'), 'attribute'),
            new DateFilterBefore(__('Before'), 'attribute'),
        ];
    }

You can also filter for specific dates only (using a single DateFilter) or force open-ended range filtering by adding just one of the other four filters.

Don't forget to add the correct use statements for the filters you need to the resource file:

use Wdelfuego\Nova4\FormattableDate\Filters\DateFilter;
use Wdelfuego\Nova4\FormattableDate\Filters\DateFilterAfter;
use Wdelfuego\Nova4\FormattableDate\Filters\DateFilterAfterOrOn;
use Wdelfuego\Nova4\FormattableDate\Filters\DateFilterBefore;
use Wdelfuego\Nova4\FormattableDate\Filters\DateFilterBeforeOrOn;

wdelfuego/nova4-formattable-date 适用场景与选型建议

wdelfuego/nova4-formattable-date 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 11.31k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2022 年 04 月 16 日, 在 PHP 生态内属于活跃度较高的组件。

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

围绕 wdelfuego/nova4-formattable-date 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-04-16