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;

统计信息

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

GitHub 信息

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

其他信息

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

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固