public function index()
{
$role = request()->query("role");
$search=request()->query('search');
$with_trashed = request()->query("inactive_users", true);
$users = $this->user->getUsers($role, $with_trashed,$search,
request()->query("pagination_limit"));
return (MemberResource::collection($users));
}
UserRepository
public function getUsers($role = null,
$with_trashed = true,$search=null, int $pagination_limit = null)
{
$terms = explode(' ', $search);
$users = User::when($with_trashed, function ($query) {
$query->withTrashed();
})->when($search, function ($query) use ($terms,$search) {
$query->where(function ($query) use ($terms,$search) {
if (count($terms) === 2) {
$query->where(function ($query) use ($terms) {
$query->where('first_name', 'like', '%' . $terms[0] . '%')
->where('last_name', 'like', '%' . $terms[1] . '%');
})->orWhere(function ($query) use ($terms) {
$query->where('first_name', 'like', '%' . $terms[1] . '%')
->where('last_name', 'like', '%' . $terms[0] . '%');
});
} else {
$query->where('first_name', 'like', '%' . $search . '%')
->orWhere('last_name', 'like', '%' . $search . '%');
}
});
})
->where('email', '!=', 'superadmin@gmail.com')
->latest();
return $pagination_limit ? $users->paginate($pagination_limit) :
$users->get();
}

