php - Complex-ish query in Laravel (Eloquent) -
i've read laravel documentation can't quite work 1 out.
does know if query possible in eloquent?
if so, how write it?
select monthname(postdate) monthname, date_format(postdate,'%m') month, year(postdate) year, count(monthname(postdate)) num postdata status = 1 group monthname, year order postdate desc
while using db::raw
whole query work, doesn't feel right me. might wanna try solution using query builder.
db::table('postdata')->select([ db::raw('monthname(postdate) monthname'), db::raw('date_format(postdate, \'%m\') month'), db::raw('year(postdate) year'), db::raw('count(monthname(postdate)) num'), ])->where('status', 1) ->groupby('monthname', 'year') ->orderby('postdate', 'desc');
it still uses db::raw
, select clause. anyway, have used postdata
model instead of db::table('postdata')
, since wouldn't regular postdata
object, i'd advise against it.
Comments
Post a Comment