问题描述
有两种模型 BoardArticle 和 BoardArticleLocation。
$articles = BoardArticle::where('board_id',$board_id)
->orderBy("id",'desc')
->paginate(20);
$boardlocation = BoardArticleLocation::select('location_top as top','location_top_text as text')
->addselect(DB::raw('CONCAT("[",group_concat(location_sub),"]") as sub'))
->where('board_article_id',$id)
->groupby('location_top')
->get();
所以,这些是我尝试过的方法。
$articles = BoardArticle::where('board_id',$searchKey,$board_id)
->select('board_articles.*')
->addselect(DB::raw('CONCAT("[",group_concat(DISTINCT location_top_text),"]") as location_text'))
->leftjoin('board_article_locations','board_articles.id','=','board_article_locations.board_article_id')
->groupby('board_articles.id')
->orderBy("id",'desc')
->paginate(20);
这个方法太慢了。
$articles = BoardArticle::where('board_id',$board_id)
->with('BoardArticleLocations')
->orderBy("id",'desc')
->paginate(20);
Models\BoardArticleLocation
public function BoardArticleLocations()
{
return $this->hasMany(BoardArticleLocation::class)
->select('location_top as top','location_top_text as text')
->addselect(DB::raw('CONCAT("[","]") as sub'))
->groupby('location_top');
}
此方法没有查找任何项目。
我该怎么办?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)