我有2个对象,第一个检索对象工作的注释,第二个检索对象成果的注释。我想在包含评论列表的单个表格中显示结果。laravel 2个对象在一个数组中的结果
$posts1 =\DB::table('posts')
->select('posts.*', 'profils.nom_profil', 'works.titre', 'profils.imagelogo', 'works.description', 'works.like', 'works.nlike')
->join('works', 'posts.work_id','=','works.id')
->join('profils', 'posts.profil_id','=','profils.id')
->where('works.profil_id',$id)
->orderBy('posts.id', 'desc')
->paginate(10);
$posts2 =\DB::table('posts')
->select('posts.*', 'profils.nom_profil', 'achievs.titre', 'profils.imagelogo', 'achievs.description', 'achievs.like', 'achievs.nlike')
->join('achievs', 'posts.achiev_id','=','achievs.id')
->join('profils', 'posts.profil_id','=','profils.id')
->where('achievs.profil_id',$id)
->orderBy('posts.id', 'desc')
->paginate(10);
鉴于:
@foreach($posts as $post)
.
.
.
@endforeach
你应该添加 - >获得()两个查询,使他们集合第一,那么你就可以合并。 – phobia82