Oh my! How do I delete this thread I'm an idiot!
In my code
{{ $products->appends(['sizes' => $sizes])->render() }}
I'm telling it to search for 'sizes' instead of 'size'.
Okay, so first I'll explain what I'm trying to do here. So picture this: there is a products page and inside this there are multiple products.
On the backend, each product has a stock. Think of a stock as in a real store, you go to the back, and that is where you may have multiple sizes of this same product. So since each product has a stock, I'm trying to filter the size to the user's request. Basically, they can choose which size(s) they want to look for.
Right now, I am using this for code:
public function getSearch(Request $request, Product $product) {
$sizes = $request->input('size');
$products = $product->whereHas('stocks', function($query) use ($sizes) {
$query->whereIn('size', $sizes);
})->paginate(12);
return view('shop.product.search')->with(['title' => $request->input('title'), 'products' => $products, 'sizes' => $sizes]);
}
This all works completely fine, but in the view, I'm trying to paginate the results. Keep in mind that I have populated the database with approximately 3,000 results. All of the results that I have put in contain 3 stocks all same size. So each product has 3 stocks. One that is size 7, one that is size 8, and finally one that is size 9. I'm trying to make it so the user can search for a size, and then be able to sift through the results page by page.
Here is my code to handle the pagination:
{{ $products->appends(['sizes' => $sizes])->render() }}
When you click page 2, I get this strange error:
SQLSTATE[HY000]: General error: 25 bind or column index out of range (SQL: select count(*) as aggregate from "products" where exists (select * from "stocks" where "stocks"."product_id" = "products"."id" and 0 = 1))
I am using SQLITE if this matters (just because I'm too lazy to setup MySQL for development. If this is the cause I will gladly take the time to setup MySQL.)
Please or to participate in this conversation.