Download the PHP package wdelfuego/nova4-formattable-date without Composer
On this page you can find all versions of the php package wdelfuego/nova4-formattable-date. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download wdelfuego/nova4-formattable-date
More information about wdelfuego/nova4-formattable-date
Files in wdelfuego/nova4-formattable-date
Package nova4-formattable-date
Short Description Formattable DateTime fields for Laravel's Nova 4
License MIT
Informations about the package nova4-formattable-date
Package deprecated
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:
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:
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:
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:
DateFilteronly shows items whose date match the filter valueDateFilterAfteronly shows items whose date is later than the filter valueDateFilterAfterOrOnonly shows items whose date is later than or on the same date as the filter valueDateFilterBeforeonly shows items whose date is earlier than the filter valueDateFilterBeforeOrOnonly 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:
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: