Skip to content
This repository was archived by the owner on Nov 30, 2018. It is now read-only.

Improve Date to be allow to use for Date From and Date To #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

nasrulhazim
Copy link

This PR enabled developers to have a nice Date From and Date To Feature - Date Range.

To enable developers to use the feature simply create new Filter, then extend the R64\Filters\DateFilter class, then define as following:

The Setup

namespace App\Nova\Filters;

class DateFrom extends Date
{
    public $date_field = 'created_at';

    public $is_date_from = true;
}
namespace App\Nova\Filters;

class DateTo extends Date
{
    public $date_field = 'created_at';

    public $is_date_to = true;
}

The Usage

...
    public function filters(Request $request)
    {
        return [
            new Filters\DateFrom(),
            new Filters\DateTo(),
        ];
    }
...

Others

Other than this feature, developers may define public $options to define Date config

@nasrulhazim nasrulhazim mentioned this pull request Nov 21, 2018
@nasrulhazim
Copy link
Author

if you don't define $is_date_from or $is_date_to, the operand will be use is =.

public $date_field is mandatory since we need to which column to be use for checking.

@beliolfa
Copy link
Contributor

beliolfa commented Nov 22, 2018

Thanks for your PR!
I think that it fits better if getDateField were an abstract method. But in the other hand I dont want to force the user to declare it if they want to use the DateFilter as usual (declaring their own apply). I dont know why but I see this feature a bit breaking.
Let me think about it :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants