I'm trying to display all products of specific user from database but I get an error Call to a member function count() on null" how can I display the products?
Controller
public function favouritelist(Request $request)
{
$products = $request->user()->favouriteProducts()->first();
return view('front.wishlist', compact('products'));
}
User.php
public function favouriteProducts(){
return $this->morphedByMany(Product::class,'favouriteable')
->withPivot(['created_at'])->orderBy('pivot_created_at', 'desc');
}
from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2BhtIcU
via IFTTT
Aucun commentaire:
Enregistrer un commentaire