Skip to content

How to deal with SoftDeletes? #80

Answered by abbasudo
tantchen asked this question in Q&A
Discussion options

You must be logged in to vote

Hey @tantchen.
Nice solution. however , i suggest creating a new filter using make:filter command as described in docs

class TrashedFilter extends Filter
{
    /**
     * Operator to detect in the query params.
     *
     * @var string
     */
    protected static string $operator = '$wt';

    /**
     * Apply filter logic to $query.
     *
     * @return Closure
     */
    public function apply(): Closure
    {
        return function ($query) {
            if ($this->value) {
                $query->withTrashed();
            }
        };
    }
}

This way end users have more control over results.

Replies: 3 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by tantchen
Comment options

You must be logged in to vote
1 reply
@tantchen
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants