2017-06-14 97 views
-1

我有这个加入的foreach laravel查询

public function deals(){ 

    $matchThese = [ 'suspended' => 0, 'status' => 1, 'approved' => 1 ]; 

    $deals = ListsDeals::where($matchThese)->orderBy('start_date')->get(); 

    $list = DB::table('lists') 
     ->join('list_has_deals', 'lists.id', '=', 'list_has_deals.list_id') 
     ->where('list_has_deals.deal_id', '=', 12) 
     ->select('lists.id') 
     ->get(); 

    $categories = DB::table('lists_categories') 
     ->join('list_has_categories', 'lists_categories.id', '=', 'list_has_categories.category_id') 
     ->where('list_has_categories.list_id', '=', $list[0]->id) 
     ->select('lists_categories.title') 
     ->get(); 

    return view("deals") 
      ->with("deals", $deals) 
      ->with("categories", $categories); 

} 

我想获得冠军的名单范畴的价值,但首先我需要获取列表中的优惠少言

我有

Deals - Lists - lists_has_deals 

Categories - Lists - lists_has_deals 

都是belongsToMany,我想在交易中获得属于与报价相关联的列表的类别。

在我的例子中,工作正常,但12需要成为$交易的foreach不是数字静态,感谢您的帮助。

回答