2014-09-01 60 views
0

我有两个表Laravel关系:心愿产品 我想根据阅读产品表PRODUCT_ID在愿望清单表,但是对于特定的用户...两个表[类似工会]

从心愿表我USER_ID这将是equall在用户ID登录阅读列第一(验证::用户() - > ID)......当这样做了,我看了产品表PRODUCT_ID从wishlist表中哪w乌尔德是一样ID在产品...

控制器:

public function getWhishlist() { 
    $wishItems = WishItem::where('user_id', '=', Auth::user()->id); 
    return View::make('wishlist')->with('wishItems', $wishItems); 
} 

查看:

@foreach ($wishItems as $wishItem) 
    {{ dd($wishItem) }} 
    <?php $getProducts = Product::find($wishItem->product_id); ?> 
    @foreach ($getProducts as $getProduct) 
     {{ $getProduct->title }} 
    @endforeach 
@endforeach 

型号:

class WishItem extends Eloquent { 
    protected $table = 'wishlist'; 
} 

{{DD($ wishItem)}} - >什么也没有发生 并没有任何反应与整个代码在所有...没有从表中的任何结果

我的问题是如何从两个表中读取??

回答

0

你实际上没有取任何东西。

试试这个

$wishItems = WishItem::where('user_id', '=', Auth::user()->id)->get(); 
+0

试图让非对象的属性(查看:C:\ XAMPP \ htdocs中\ laravel-网店\ laravel \程序\意见\ wishlist.blade.php) – user3809590 2014-09-01 13:41:11

+0

你能告诉wishItems vardump从控制器的输出? – 2014-09-01 13:45:17

+0

ooohhh ..这是巨大的.... – user3809590 2014-09-01 13:47:51