illizian / nova-carbon-modifier-field
A field for allowing a User to configure a "Carbon Modifier"
Installs: 35
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Language:JavaScript
Requires
- php: >=7.1.0
README
Description
A Laravel Nova field for describing a DateTime modification using Carbon methhods.
Demo
Installation
The package can be installed through Composer.
composer require illizian/nova-carbon-modifier-field
Usage
Add a \Illizian\NovaCarbonModifier\NovaCarbonModifier
, field to your fields, like so:
/* ... */ use \Illizian\NovaCarbonModifier\NovaCarbonModifier; /* ... */ class Example extends Resource { /* ... */ public function fields(Request $request) { return [ /* ... */ NovaCarbonModifier::make(__('Modifier'), 'modifier'), ]; }
You may also provide a list of popular modifiers, should you wish with the popular(array $modifiers)
method:
/* ... */ use \Illizian\NovaSuggestWrapper\NovaSuggestWrapper; /* ... */ class Example extends Resource { /* ... */ public function fields(Request $request) { return [ /* ... */ NovaCarbonModifier::make(__('Modifier'), 'modifier') ->popular('startOfWeek,hour:10,minute:0', 'subDays:1,hour:13,minute:0'), ]; }
As you can see above, a modifier is stored as a comma-seperated string, it takes the following format:
"<method>:<parameter>"
"<method>:<parameter>,<method>:<parameter>,<method>:<parameter>"
"<method>"
"<method>,<method>,<method>"
"<method>,<method>:<parameter>,<method>:<parameter>,<method>,<method>:<parameter>,<method>"
etc...
The field class provides a static helper for applying this modifier string to a Carbon instance for your convenience:
use \Carbon\Carbon; use \Illizian\NovaSuggestWrapper\NovaSuggestWrapper; $date = Carbon::now(); $modifiers = 'startOfWeek,hour:10,minute:0'; $date_modified = NovaCarbonModifier::applyModifier($date, $modifiers);
License
The MIT License (MIT). Please see License File for more information.