I'm creating a wishlist ,so that user can be able to save item to wishlist. I have products table, wishlist table which has user_id and product_id columns and also I have pivot table product_wishlist table which has foreign key product_id and wishlist_id. The problem is it doesn't display the product information like price, name etc and it shows no errors, I don't know if my relations are wrong or there is something else, how can I fix this ?
Wishlist.php
class Wishlist extends Model
{
protected $table = "wishlist";
protected $fillable=['product_id','user_id'];
public function user(){
return $this->belongsTo(User::class);
}
public function product(){
return $this->belongsToMany(Product::class,'product_wishlist','wishlist_id', 'product_id');
}
}
Product.php
public function wishlist(){
return $this-belongsToMany(Wishlist::class);
}
Wishlist controller
public function index()
{
$user = Auth::user();
$wishlists = Wishlist::with('product')
->where('user_id', $user->id)
->orderby('id', 'desc')
->paginate(6);
//dd($wishlists);
return view('front.wishlist', compact('user', 'wishlists'));
}
Blade
@foreach($wishlists as $wishlist)
<h3 >USD </h3>
<h4 >USD </h4>
@endforeach
from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/31h8pD1
via IFTTT
Aucun commentaire:
Enregistrer un commentaire