5 months ago

show other Products owned by the owner

Posted 5 months ago by SPL3S

I have a product page where all the product info is shown, and at the bottom, I want to show other products owned by the owner, but I can't think of the way doing it...

I have $product->owner_id which displays the owner's id 'SPL3S' but if I try to do

@if($product->owner_id == $product->owner_id)

   @foreach($products as $product)
       {{ $product->name }}


I still get all the products owned by other users too. I also tried to store owner_id as

$owner = $product->owner_id;

and then doing same if rule

@if($product->owner_id == $owner)

    @foreach($products as $product)
        {{ $product->name }}


but still get all the products in the table

my controller for showing the product is

    public function show($slug) {

        $products = Product::all();
        $product = Product::where('slug', $slug)->firstOrFail();

        return view('products.product', compact('product', 'products'));

Please sign in or create an account to participate in this conversation.