jeudi 31 octobre 2019

Get property (none object) laravel

I have a recommends table which has user_id and product_id column and I'm trying to display mostly viewed products but I get an error

Trying to get property of non-object from the view,

if I dd($viewed) it shows all the products correctly but the problem is it can't display products and throws an error, any idea on how to solve this?

Controller

$viewed = Recommends::with('product')
   ->where('user_id', Auth::user()->id)
   ->select('product_id')
   ->inRandomOrder()
   ->groupBy('product_id')
   ->orderby('product_id', 'DESC')
   ->take(8)
   ->get();

Blade file

@foreach($viewed as $view)
 <h1>USD: </h1>
 <h2>USD: </h2>
@endforeach


via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire