Skip to content

Allow all filters for a generic purpose query #836

Answered by fbramato
fbramato asked this question in Q&A
Discussion options

You must be logged in to vote

I've figured out by myself, wasnt so hard :)

public function getRecords(Request $request)
    {
        $query = QueryBuilder::for($request->class);

        $attributes = $query->getSubject()->getModel()->getFillable();
        $attributes[] = $query->getSubject()->getModel()->getKeyName();

        $query->allowedFilters($attributes)->allowedSorts($attributes);

        return $query->get();
    }

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by fbramato
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant