2016-04-28 106 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