查询构建器中的问题 - laravel 5.2

时间:2016-04-28 12:27:50

标签: laravel-5.2 laravel-query-builder

我有一个给我错误的查询

$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. 如何解决此错误?

2 个答案:

答案 0 :(得分:2)

你必须将雄辩的结果转换为数组

->get()->toarray();

答案 1 :(得分:0)