问题在查询生成器 - laravel 5.2
问题描述:
我有一个查询这给我的错误问题在查询生成器 - 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
我有这些问题
- 这是一个很好的方式做它?或者我们可以改进它?
- 如何解决这个错误?
其中哪一行有这个错误?正如它清楚地表明你正在尝试将其用作数组。其次,你可以使用[Relationships](https://laravel.com/docs/5.0/eloquent#relationships)来清理它。 – Abbasi