Filtering multiple request parameters This is pretty straightforward, it takes requests from the frontend, checking if it is present on the request, if it does, an action is taken for that if statement.
I wonder if there is a way to remove some if statements or make it less complicated.
private function applyFiltering($query, $request)
{
    if ($request-&gt;has('active_group')) {
        $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]);
        });
    }

    if ($request-&gt;has('waiting_group')) {
       $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);
         });
    }


    if ($request-&gt;has('meeting_group')) {
        $query-&gt;where('type_id', 2);
    }

    if ($request-&gt;has('comp_meeting_group')) {
        $query-&gt;where('type_id', 4);
    }

    if ($request-&gt;has('completed_group')) {
            $query-&gt;whereHas('userStatus', function ($query) use ($request) {
                $query-&gt;where('user_id', $request-&gt;user()-&gt;id)-&gt;where('status_id', 1);
            });
    }

    if ($request-&gt;has('canceled_group')) {
        $query-&gt;whereHas('userStatus', function ($query) use ($request) {
            $query-&gt;where('user_id', $request-&gt;user()-&gt;id)-&gt;where('status_id', 6);
        });
    }


    if ($request-&gt;has('shift_group')) {
        $query-&gt;where('status_id', 1)-&gt;where('type_id', 6);
    }

    if ($request-&gt;has('announce_group')) {
        $query-&gt;where('type_id', 3);
    }

    if ($request-&gt;has('task_id')) {
        $query-&gt;where('id', 'like', '%' . $request-&gt;input('task_id') . '%');
    }

    if ($request-&gt;has('task_statuses')) {
        $statuses = $request-&gt;input('task_statuses');
        $query-&gt;whereIn('status_id', $statuses);
    }
    if ($request-&gt;has('task_types')) {
        $statuses = $request-&gt;input('task_types');
        $query-&gt;whereIn('type_id', $statuses);
    }
    if ($request-&gt;has('task_priorities')) {
        $statuses = $request-&gt;input('task_priorities');
        $query-&gt;whereIn('priority_id', $statuses);
    }
    if ($request-&gt;has('task_invite_users')) {
        $toUsers = $request-&gt;input('task_invite_users');
        $query-&gt;whereHas('taskAssignment', function ($query) use ($request, $toUsers) {
            $query-&gt;whereIn('assigned_to', $toUsers);
        });

        // $query-&gt;whereIn('to_user_id',$statuses);
    }

    if ($request-&gt;has('task_users')) {
        $byUsers = $request-&gt;input('task_users');
        $query-&gt;whereHas('taskAssignment', function ($query) use ($request, $byUsers) {
            $query-&gt;whereIn('assigned_by', $byUsers);
        });
    }
}
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);
         });
    })
    ........
    ........
    ........
}
```