Doubt in laravel driver with php

0

I have a problem with the controller, I'm looking for a product and at the same time I'm looking for a product that I have related up to here I have no problem using this driver:

 public function show($id)
        {

            $producto = Producto::find($id);
            $relacionado = relaciones::where('idrelacion', $id)->find();




            return view('products.show', compact('producto', 'relacionado'));
        }

But when I try to look up the related product in the base table it gives me the following error error: Property [kinship_id] does not exist on this collection instance. "but in the table relations if there is kinship_id" This is the controller I use:

 public function show($id)
  {

                $producto = Producto::find($id);
                $relacionado = relaciones::where('idrelacion', $id)->find();
                $productorecomendado = Producto::where('id', $relacionado->producto_id)-->find();



                return view('products.show', compact('producto', 'productorecomendado'));
            }

As you can see what I'm trying to do is to look again in the table for products with the id that the related variable throws at me but I do not get it ..

    
asked by Lendy Rodriguez Silva 16.11.2018 в 23:16
source

1 answer

1

Solved change Find() by First() and how to write variable $relacionado->producto_id by $relacionado['producto_id'] .

public function show($id)
  {

                $producto = Producto::find($id);
                $relacionado = relaciones::where('idrelacion', $id)->first();
                $productorecomendado = Producto::where('id', $relacionado[producto_id])->get();

                return view('products.show', compact('producto', 'productorecomendado'));
            }
    
answered by 17.11.2018 в 12:26