A Laravel Nova field for describing a DateTime modification using Carbon methhods.
The package can be installed through Composer.
composer require illizian/nova-carbon-modifier-field
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);
The MIT License (MIT). Please see License File for more information.