Filtering multiple request parameters
You could try something like this:

private function applyFiltering($query, $request)
{

    $query-&gt;when($request-&gt;has('active_group'), function($query) use($request) {
        $query-&gt;whereNotIn('status_id', [1, 6, 4]);
        $query-&gt;whereHas('userStatus', function ($query) use ($request) {
            $query-&gt;where('user_id', $request-&gt;user()-&gt;id)-&gt;whereNotIn('status_id', [1, 6, 4]);
        });
    })-&gt;when($request-&gt;has('waiting_group'), function($query) use ($request) {
        $query-&gt;whereNotIn('status_id', [1, 6]);
        $query-&gt;whereHas('userStatus', function ($query) use ($request) {
              $query-&gt;where('user_id', $request-&gt;user()-&gt;id)-&gt;whereNotIn('status_id', [1, 6])-&gt;where('status_id',4);
         });
    })
    ........
    ........
    ........
}
```