Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why the data in wishlist can't show [closed]

Tags:

php

laravel

the product data already store in database but the data cannot show in the wishlist page.How do i solve it??

public function  wishList(Request $request)
{
    $products = wishlist::where('wishlist.pro_id','=','products.id')->get();
    return view('wishlist',compact('products'));
}

public function addWishList(Request $request){
    $wishList = new wishList;
    $wishList->user_id = Auth::user()->id;
    $wishList->pro_id = $request->pro_id;
    $wishList->save();
}

this is the wishlist page that i want to show the product.. is it the data cannot get from the database?

<tbody>
@forelse($products as $product)
<tr>
    <td>
        <img src="{{url('/assets/images/products')}}/{{\App\Product::findOrFail($product->product)->feature_image}}" alt="">
    </td>
    <td>
        /*product name*/
        <a href="{{url('/product',$product->id)}}">
        {{$product->title}}
        </a>
    </td>

</tr>

@empty
    <tr>
        <td colspan="6">
            <h3>Your WishList Is Empty</h3>
        </td>
    </tr>
@endforelse
<tr>
    <td colspan="4">
        <a href="{{url('/')}}" class="shopping-btn">{{$language->continue_shopping}}</a>
    </td>
</tr>
</tbody>
like image 841
chong wenda DeadPool Avatar asked Nov 20 '25 11:11

chong wenda DeadPool


1 Answers

I think the problem is in wishlist query:

$products = wishlist::where('wishlist.pro_id','=','products.id')->get();

This will produce sql query

SELECT * FROM wishlist WHERE wishlist.pro_id = 'products.id'

It will not throw mysql exception as 'products.id' is string and I don't think it is the query which you want.

I think you have to join your wishlist on products table and then use whereRaw or where(DB::raw('...') Query Builder syntax

whereRaw:

Wishlist::whereRaw('wishlist.pro_id = products.id')->get()

where:

Wishlist::where(DB::raw('wishlist.pro_id = products.id'))->get()
like image 176
Malkhazi Dartsmelidze Avatar answered Nov 22 '25 03:11

Malkhazi Dartsmelidze



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!