0

我有一个给我错误的查询

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

2 回答 2

2

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

->get()->toarray();
于 2016-04-28T12:40:09.173 回答
0
  • 看看雄辩的关系

  • 使用$p->id而不是$p['id'].

于 2016-04-28T14:37:08.570 回答