2016-04-28 169 views
0

我有一個查詢這給我的錯誤問題在查詢生成器 - laravel 5.2

$query= DB::table('crm_listings as l') 
     ->leftJoin('crm_location as loc', 'l.area_location_id', '=', 'loc.loc_id') 
     ->select('l.id','l.name','l.price', 'loc.lat', 'loc.lon') 
    ->get(); 

    foreach($query as $i=>$p) { 

    $images_query =DB::table('crm_listings_images')->where('listing_id', $p['id'])->select('image')->get(); 
    $query[$i]['images'] = $images_query; 

    } 
    return $query; 

的錯誤是Cannot use object of type stdClass as array

我有這些問題

  1. 這是一個很好的方式做它?或者我們可以改進它?
  2. 如何解決這個錯誤?
+0

其中哪一行有這個錯誤?正如它清楚地表明你正在嘗試將其用作數組。其次,你可以使用[Relationships](https://laravel.com/docs/5.0/eloquent#relationships)來清理它。 – Abbasi

回答

2

必須雄辯的結果轉換爲數組

->get()->toarray(); 
+0

錯誤調用成員函數toarray()數組 – DOE

+0

請把你的代碼 – Ehsan

+0

閱讀我的問題..所有的代碼是 – DOE