New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Filtering #4
Comments
Hi @it-can, Depending on your set up there are a number of ways you could approach this. You can do the following From the query builder: $productMeta = Meta::select('key', 'value')->selectRaw('count(*) as count')
->where('meta.metable_type', '=', Product::class);
})->groupBy(['key', 'value'])
->get();
// returns a collection of records, which each have a key, value and count attribute
// loop as necessary for your needs. Assuming you have all products in a collection: $counts_by_width = $products->groupBy(function($product){
return $product->getMeta('width', null);
})->map(function($group){
return count($group);
});
// outputs [ '10mm' => 4, '20mm' => 1] Hope this helps |
ok thanks will test it... 👍 |
Hey @frasmage, does the metable_type selection work correctly? When running this on my db, it doesn't return results.
but when removing the metable_type it works and gives results...
|
Yes, the metable_type is necessary to only get back records that are attached to products, as opposed to any other models that you have applied meta to. I'm not able to tell what is misconfigured from your SQL example. Could you show me the code executing this and/or a few example rows from your DB? |
It needs a double slash then it works... |
@it-can right. Are you writing the query yourself or through the query builder, as above? The query builder should handle that automatically. |
Yeah it works, I was trying the query in phpmyadmin for testing |
@it-can Cool. Anything else, or shall I close this issue? |
Close it... thanks for the help! |
Hi I am using your package for a sort of webshop with a couple of products. The products have multiple meta values. Is there a easy way to create some sort of product meta filtering?
Something like this:
Width:
Height:
The text was updated successfully, but these errors were encountered: