'query not stacking in laravel

I have a query that i am trying to insert a value based on a forum post results. Boiling it down to this

$users->whereIn('id', $viewedIds);
$rdata = $users->with('profile')->where('gender', '=', $searchGender)->orderBy('last_login')->simplePaginate(8);

Which doesn't work. but this does.

$rdata = $users->with('profile')->where('gender', '=', $searchGender)->whereIn('id', $viewedIds)->orderBy('last_login')->simplePaginate(8);

but I cant do that with form post data.

Any ideas?



Solution 1:[1]

I needed to start my query with $users = User::query() instead of $users = new User();

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Terre Porter