I'm displaying similar products in my Product Page. I have a query that finds all products with a similar brand_id or cat_id for the product being viewed. My problem is that it also displays the current product being viewed in the similar section. I need to make it so it removes the current product being viewed from the similar products section.
This is the query I have right now. ( The 'id', '!==', $product->id part is not working)
/**
* Show a Product in detail
*
* @param $product_name
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/
public function show($product_name) {
// Find the product by the product name in URL
$product = Product::ProductLocatedAt($product_name);
// Select All from "products" table where the brand_id is = to the current product being viewed with its brand_id, OR where
// the category_id is = to the current product category Id being viewed. This is so we can display similar products for a // particular product being shown.
$similar_product = Product::where('brand_id', '=', $product->brand_id)
->where('id', '!==', $product->id)
->orWhere('cat_id', '=', $product->cat_id)->get();
return view('pages.show_product', compact('product', 'similar_product'));
}
******** EDIT ******** I'm getting this when using your query method: