hootlex / laravel-moderation

A simple Content Moderation System for Laravel 5.* that allows you to Approve or Reject resources like posts, comments, users, etc.
MIT License
526 stars 68 forks source link

Building a Filter Query for ModerationStatus::APPROVED #55

Open dev-ns8 opened 3 years ago

dev-ns8 commented 3 years ago

Hello I am maintaining a project that uses this library for moderation, and on some of our content we like to filter by 'Approved', 'Pending' , 'Rejected', and 'Postponed'.

We have a custom Status Filter that extends Laravel\Nova\Filters\Filter. In this class, we define an apply method as such:

    public function apply(Request $request, $query, $value)
    {
        switch($value) {
            case $this->all:
            default:
                $query = $query->withAnyStatus();
                break;
            case ModerationStatus::PENDING:
                $query = $query->pending();
                break;
            case ModerationStatus::APPROVED:
                break;
            case ModerationStatus::REJECTED:
                $query = $query->rejected();
                break;
            case ModerationStatus::POSTPONED:
                $query = $query->postponed();
                break;
        }

        return $query;
    }

Now I am sorry if this is the wrong place to be asking this, but as it pertains to Laravel and Nova, how can I add an approved() filter to the $query() that is being returned? I see this query is of type \Illuminate\Database\Eloquent\Builder and I kind of half expected to see this library extend that somewhere in the code. This however is not the case and digging through the API reference for \Illuminate\Database\Eloquent\Builder I don't see any reference to these methods being performed on the $query in the above function.

Could someone maybe point me in the right direction of where to look? Is hootlex not fully compatible with Laravel and Nova and therefore doesn't offer a way to filter by ModerationStatus::APPROVED ?

Any help would be greatly appreciated