honestly I dont have much information. I want a list of similar products to be displayed in comparison section of product details page. I need some general help in how to database should change and if I need any new table? or they are aquired on the fly?
@danimohamadnejad You don't need new tables, you just need a new query based on the viewed product's parameters.
Let's say you view a notebook
category: Laptops
sub-category: Apple
ram: 8gb
colour: Silver
now you just need to take products from laptops category, apple sub-category`, or where laptops have 8gb of ram, or colour silver. obviously it depends on your project structure. hope it helps a little)
@danimohamadnejad I don't have a project to experiment with, but I'll try to give you some hints, also this article may help you
class ProductsController extends Controller
{
public function show(Product $product)
{
// take current product category/details/parameters
$categoryId = $product->category->id // or $product->categories->pluck('id')
// take product's options
$options = $product->options;
// now just filter your Product model with above details
$similarProducts = Product::whereHas([
'category' => function($q) use ($categoryId) {
$q->where('id', $categoryId);
}
])
->orWhereHas() // ...
->orWhereHas(); // ..
return view('products.show', compact('product', 'similarProducts'));
}
}
this is good solution. each product has many categories so I can easily get leaf category to get similar products.
do you have any Idea to help me make the criteria more accurate like those whereHas which you have proposed. what should criteria be like? should I specify if the filter should be displayed in similar items when I am creating new filter???