Makes working with DateTime fields in Laravel's Nova easier

Overview

This package adds a DateTime field with support for a global DateTime format, syntactic sugar for formatting individual DateTime fields and powerful date filters for Index views. It can serve as a base for more extensions and improvements with regard to DateTime fields and logic in Laravel's Nova 4.

Installation

composer require wdelfuego/nova-datetime

Usage

Formatting DateTime fields globally

  1. First, publish this package's config file by running:

    php artisan vendor:publish --provider="Wdelfuego\Nova\DateTime\ServiceProvider"
  2. Then, set the format you want to use for all of your DateTime fields in config/nova-datetime.php, for example:

    return [
        'globalFormat' => 'Y-M-d H:i:s',
    ];
    
  3. In your Nova resource, replace all instances of Laravel\Nova\Fields\DateTime with instances of Wdelfuego\Nova\DateTime\Fields\DateTime by adding this use statement:

    use Wdelfuego\Nova\DateTime\Fields\DateTime;
    

This allows you to apply the global format to all DateTime fields in your own Nova resources automatically.

To automatically apply the global DateTime format to the 'Action Happened at' column of the action events in your resources' action logs as well, install the wdelfuego/nova-actions package.

Formatting individual DateTime fields

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

The withDateFormat helper is added automatically to all DateTime fields in your project (including Nova's own, so you don't have to use a custom DateTime field) and allows you to directly set the format you want the field to be displayed in:

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

It is simple syntactic sugar around the displayUsing method that works on DateTime fields since Nova 4.2.4.

Filtering resources by DateTime fields

You can use Laravel's native filterable method on your DateTime fields for a standard date range filter or use any combination of the date filters below to give your end users powerful ways to filter their Nova resources from the Index view.

  • OnDate only shows items where the DateTime field matches a specific date
  • NotOnDate only shows items where the DateTime field is not on a specific date
  • AfterDate only shows items where the DateTime field is after a specific date
  • AfterOrOnDate only shows items where the DateTime field is either after or on a specific date
  • NotAfterDate only shows items where the DateTime field is not after a specific date (this is a fully equivalent alias to BeforeOrOnDate)
  • BeforeDate only shows items where the DateTime field is before a specific date
  • BeforeOrOnDate only shows items where the DateTime field is either before or on a specific date
  • NotBeforeDate only shows items where the DateTime field is not before a specific date (this is a fully equivalent alias to AfterOrOnDate)

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

For example, you could make a standard date range filter that allows users to exclude a specific date like this:

use Wdelfuego\Nova\DateTime\Filters\AfterDate;
use Wdelfuego\Nova\DateTime\Filters\BeforeDate;
use Wdelfuego\Nova\DateTime\Filters\NotOnDate;
    public function filters(NovaRequest $request)
    {
        return [
            new AfterDate(__('After'), 'attribute'),
            new BeforeDate(__('Before'), 'attribute'),
            new NotOnDate(__('But not on'), 'attribute'),
        ];
    }

You can also filter for specific dates only using just a single OnDate filter, or force open-ended range filtering by adding just one of the After or Before filters.

Support

For any problems, questions or remarks you might have, please open an issue on GitHub.

You might also like...
Laravel Nova Ban simplify blocking and banning Eloquent models.
Laravel Nova Ban simplify blocking and banning Eloquent models.

Laravel Nova Ban Introduction Behind the scenes cybercog/laravel-ban is used. Contents Installation Usage Prepare bannable model Prepare bannable mode

🖼️ Laravel Nova Field for uploading and cropping images using Slim Image Cropper
🖼️ Laravel Nova Field for uploading and cropping images using Slim Image Cropper

🖼️ Laravel Nova Field for uploading and cropping images using Slim Image Cropper

A customisable Laravel Nova card that fetches data through ajax calls.
A customisable Laravel Nova card that fetches data through ajax calls.

Ajax Table Card Description A customisable Laravel Nova card that fetches data through ajax calls. Why? To allow displaying certain data on the dashbo

Laravel Nova filter for Spatie/laravel-tags

SpatieTagsNovaFilter This package allows you to filter resources by tags. (using the awesome Spatie/laravel-tags and Vue-MultiSelect ) Installation Fi

Webhook Manager for Laravel Nova
Webhook Manager for Laravel Nova

Webhook Manager for Laravel Nova A Laravel Nova tool that allows users to create and manage webhooks based on Eloquent Model events. A tool for Larave

A minimalistic event calendar Tool for Laravel's Nova 4
A minimalistic event calendar Tool for Laravel's Nova 4

Event calendar for Laravel Nova 4 An event calendar that displays Nova resources or other time-related data in your Nova 4 project on a monthly calend

This tool gives you the ability to set the default collapse state for Nova 4.0 menu items.

Nova Menu Collapsed This tool gives you the ability to set the default collapse state for Nova 4.0 menu items. Requirements php: =8.0 laravel/nova: ^

A Laravel Nova tool for viewing your application logs
A Laravel Nova tool for viewing your application logs

This package makes it easy to view your Laravel application logs inside of Nova. It even supports polling. Installation You can install the Nova tool

Laravel Nova's Queued Export As CSV Action

Laravel Nova's Queued Export As CSV Action Installation To install through composer, run the following command from terminal: composer require "nova-k

Comments
  • Support timezone!

    Support timezone!

    Hi! I configured timezone in config/app.php, for example:

        'timezone' => 'Europe/Moscow',
    

    Then I added this DateTime field and Nova default DateTime field:

                \Wdelfuego\Nova\DateTime\Fields\DateTime::make(__('Date 1'), 'date'),
                \Laravel\Nova\Fields\DateTime::make(__('Date 2'), 'date'),
    

    and I saw:

    image

    Nova default DateTime field show time with applying timezone. This DateTime field show time without applying timezone.

    enhancement implemented 
    opened by 4n70w4 8
  • Format being ignored...

    Format being ignored...

    Trying to set the format using globalFormat (and have tried inline as well). Ripping my hair out!

    Getting an error as below.. Screenshot 2022-10-28 212715

    Seems like globalFormat & have tried inline withDateFormat are being ignored. Screenshot 2022-10-28 213054

    Any ideas?

    Nova 4.17.1

    Everything up to date.

    invalid 
    opened by martyn62 4
  • Laravel Nova v4.12.14 breaks this field

    Laravel Nova v4.12.14 breaks this field

    I just updated my nova installation to the latest version as described in the title and the datetime fields unfortunately no longer display anything.

    As mentioned here they messed up the displayUsing function.

    You probably don't have to do anything because it's their problem but I'll keep you posted if it's fixed or not in the next version.

    dependency-issue 
    opened by Sotiris-k 3
  • Add a customizable Date/DateTime field with custom picker

    Add a customizable Date/DateTime field with custom picker

    Nova 4 defers formatting of Date/DateTime values in pickers to the browser by using its default picker implementation.

    Many users have requested ways to customize the picker in different ways.

    A custom DateTime field that implements its own customizable DateTime picker would be a super valuable addition to this package.

    enhancement 
    opened by wdelfuego 5
Owner
wdelfuego
wdelfuego
This Laravel Nova package adds a Trumbowyg field to Nova's arsenal of fields.

Nova Trumbowyg Field This Laravel Nova package adds a Trumbowyg field to Nova's arsenal of fields. Requirements php: >=8.0 laravel/nova: ^4.0 Installa

outl1ne 3 Sep 25, 2022
This Laravel Nova tool lets you run artisan and bash commands directly from Nova 4 or higher.

Laravel Nova tool for running Artisan & Shell commands. This Nova tool lets you run artisan and bash commands directly from nova. This is an extended

Artem Stepanenko 17 Dec 15, 2022
This Laravel Nova package allows you to manage media and media fields

Nova Media Hub This Laravel Nova package allows you to manage media and media fields. Requirements php: >=8.0 laravel/nova: ^4.0 Features Media Hub UI

outl1ne 25 Dec 22, 2022
Composer package which adds support for HTML5 elements using Laravels Form interface (e.g. Form::date())

Laravel HTML 5 Inputs Composer package which adds support for HTML5 elements by extending Laravel's Form interface (e.g. Form::date()) Adds support fo

Small Dog Studios 11 Oct 13, 2020
A package to flash multiple messages using Laravels default session message flashing system

Flash multiple advanced messages with both text, messages and links An opinionated solution for flashing multiple advanced messages from the backend a

Bilfeldt 6 Jan 18, 2022
Adds a way to write php and run it directly in Laravels' Artisan Tinker.

Adds a way to write php in PhpStorm/IDEA and run it directly as if through laravel artisan tinker - allowing you to quickly run a piece of code with a

Robbin 120 Jan 2, 2023
The Popular Datetime, Flatpickr Picker as a Filament Form Field

Flatpickr Date/Time Picker as a Filament Field Flatpickr is one of the most popular js datepickers. This filament plugin allows you to use flatpickr a

Savannabits 4 Aug 29, 2022
List of 77 languages for Laravel Framework 4, 5, 6, 7 and 8, Laravel Jetstream , Laravel Fortify, Laravel Breeze, Laravel Cashier, Laravel Nova and Laravel Spark.

Laravel Lang In this repository, you can find the lang files for the Laravel Framework 4/5/6/7/8, Laravel Jetstream , Laravel Fortify, Laravel Cashier

Laravel Lang 6.9k Jan 2, 2023
This repo is for the Laracon 2021 talk "Manage SEO with Laravel and Nova"

About Laravel Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experie

Kristin 7 Dec 9, 2022
⚙️Laravel Nova Resource for a simple key/value typed setting

Laravel Nova Resource for a simple key/value typed setting Administer your Laravel Simple Setting in Nova Pre-requisites This Nova resource package re

elipZis 5 Nov 7, 2022