SQLSTATE[42S22]: Column not found: 1054 Unknown column 'products.wishlist_id' in 'where clause' (SQL: select * from products
where products
.wishlist_id
= 1 and products
.wishlist_id
is not null and products
.deleted_at
is null)
In my controller >>>
public function index() {
$wishlist_items = Wishlist::where('user_id', Auth::user()->id)->get();
foreach($wishlist_items as $item) {
dd($item->getProducts()->get());
}
}
Wishlist.php >>>
public function getProducts() {
return $this->hasMany(Product::class);
}
Product.php >>>
public function getWishlist() {
return $this->belongsTo(Wishlist::class);
}
Migration table >>>
Schema::create('wishlists', function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('product_id');
$table->unsignedBigInteger('user_id');
$table->timestamps();
$table->foreign('product_id')->references('id')->on('products');
$table->foreign('user_id')->references('id')->on('users');
});