如何将SELECT语句转换为Eloquent?

时间:2019-06-01 04:17:21

标签: laravel-5 eloquent

这在现有网站上有效,尝试转换为Laravel 5.8代码:

git pull

我尝试过:

import pinboard
api_key = "xxxxx"
pb = pinboard.Pinboard(api_key)
parms = {
    "url": "https://blogs.unity3d.com/cn/2018/11/19/choosing-the- 
     resolution-of-your-2d-art-assets/",
    "description": "Choosing the resolution of your 2D art assets – Unity Blog",
}
print(pb.posts.update())%

我知道了

  

错误:SQLSTATE [42000]:语法错误或访问冲突:1055   'amohdb.posts.created_at'不在GROUP BY中(SQL:SELECT   DATE_FORMAT(created_at,'%M%Y')AS'article',DATE_FORMAT(created_at,   '%m')AS'm',DATE_FORMAT(created_at,'%Y')AS'y',COUNT(id)AS'total'   FROM帖子GROUP BY DATE_FORMAT(created_at,'%Y%M')ORDER BY m DESC)

1 个答案:

答案 0 :(得分:0)

我认为答案要简单得多

$archives =  Post::select(DB::raw("DATE_FORMAT(created_at, '%M %Y') as article"),
DB::raw("COUNT(id) as total"))
->groupBy('article')
->get();