【发布时间】:2017-04-10 16:49:15
【问题描述】:
我有 2 个对象,第一个检索对象作品的 cmets,第二个检索对象成就的 cmets。我想在包含 cmets 列表的单个表中显示结果。
$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
【问题讨论】:
-
你应该将 ->get() 添加到两个查询中,先将它们变成集合,然后才能合并。
标签: php sql laravel eloquent query-builder