craftware / laravel-nova-date-range-filter
A Laravel Nova date range filter. A fork from pos-lifestyle/laravel-nova-date-range-filter
Installs: 276
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 52
Open Issues: 0
Language:Vue
Requires
- php: >=7.1
- laravel/framework: ^5.8 || ^6.0 || ^7.0 || ^8.0 || ^9.0 || ^10.0 || ^11.0
- laravel/nova: ^2.0 || ^3.0
Requires (Dev)
- roave/security-advisories: dev-master
This package is auto-updated.
Last update: 2024-11-05 16:19:42 UTC
README
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 craftware/laravel-nova-date-range-filter
Usage
Simply add this filter to the filters
method in your Nova resource.
use Illuminate\Http\Request; use Craftware\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.
Configuration
All available settings are provided by the included Config
enum. See the full example below how to use it.
Full Example
use Illuminate\Http\Request; use Craftware\DateRangeFilter\DateRangeFilter; use Craftware\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, ]), ]; } }