Code Monkey home page Code Monkey logo

laravel-nova-date-range-filter's Introduction

Laravel Nova Date Range Filter

Packagist Packagist Version

About

This is a configurable and ready to use filter for Laravel Nova 2 based on Nova's own date filter that displays a date range picker.

Installation

To install the filter run the following command in your Laravel Nova project:

composer require pos-lifestyle/laravel-nova-date-range-filter

Usage

Simply add this filter to the filters method in your Nova resource.

use Illuminate\Http\Request;
use PosLifestyle\DateRangeFilter\DateRangeFilter;

class CustomResource extends Resource
{
    public function filters(Request $request): array
    {
        return [
            new DateRangeFilter(),
        ];
    }
}

By default, this will create a filter named "Created at" which applies the selected date range to the created_at database column.

Customization

The filter takes up to three arguments to customize it to your needs.

Parameter Type Description Default
Name String The name of the filter how it should appear in the filter dropdown list. "Created at"
Column String The name of the database column on which the selected date range should be applied to. Illuminate\Database\Eloquent\Model::CREATED_AT
Settings Array An array of settings to customize the filter. See the configuration section below for details. []

Configuration

All available settings are provided by the included Config enum. See the full example below how to use it.

Setting Type Description Default
ALLOW_INPUT Boolean Allows the user to enter a date directly into the input field. false
DATE_FORMAT String A string of characters which are used to define how the date will be displayed in the input box. The supported characters are defined in this table. "Y-m-d"
DEFAULT_DATE Array Sets the initial selected dates.

Supply an array of date strings which follow the format Y-m-d.
null
DISABLED Boolean Entirely disables the filter. false
ENABLE_TIME Boolean Enables the time picker. false
ENABLE_SECONDS Boolean Enables seconds in the time picker. false
FIRST_DAY_OF_WEEK Integer Sets the first day of the week (0 = Sunday, 1 = Monday etc.). If a custom locale is used, this setting has no effect. 0
LOCALE String Localizes the filter. Available locales can be found here. "default"
MAX_DATE String The maximum date that a user can pick to (inclusive). null
MIN_DATE String The minimum date that a user can start picking from (inclusive). null
PLACEHOLDER String The text that is shown in the empty input box. __('Choose date range')
SHORTHAND_CURRENT_MONTH Boolean Shows the month using the shorthand version (e.g. Sep instead of September). false
SHOW_MONTHS Integer The number of months that should be showed. 1
TIME24HR Boolean Displays the time picker in 24 hour mode without AM/PM selection when enabled. false
WEEK_NUMBERS Boolean Enables the display of week numbers in the calendar. false

Full Example

use Illuminate\Http\Request;
use PosLifestyle\DateRangeFilter\DateRangeFilter;
use PosLifestyle\DateRangeFilter\Enums\Config;

class CustomResource extends Resource
{
    public function filters(Request $request): array
    {
        return [
            new DateRangeFilter('Created at', 'created_at', [
                Config::ALLOW_INPUT => false,
                Config::DATE_FORMAT => 'Y-m-d',
                Config::DEFAULT_DATE => ['2019-06-01', '2019-06-30'],
                Config::DISABLED => false,
                Config::ENABLE_TIME => false,
                Config::ENABLE_SECONDS => false,
                Config::FIRST_DAY_OF_WEEK => 0,
                Config::LOCALE => 'default',
                Config::MAX_DATE => '2019-12-31',
                Config::MIN_DATE => '2019-01-01',
                Config::PLACEHOLDER => __('Choose date range'),
                Config::SHORTHAND_CURRENT_MONTH => false,
                Config::SHOW_MONTHS => 1,
                Config::TIME24HR => false,
                Config::WEEK_NUMBERS => false,
            ]),
        ];
    }
}

Screenshots

Default configuration Showing 2 months
Date range filter (default) Date range filter (2 months)

laravel-nova-date-range-filter's People

Contributors

ashwinmram avatar cyruscollier avatar jcsoriano avatar jhae-de avatar niekbr avatar schroedan avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.