Group Eloquent

Posted 11 months ago by thesogafoi

hey Guys i try to Group my Posts By Year and month but give me an error i searched a lot but i cannot fix this can U help me

public function scopeArchives($query){
        $query->selectRaw(' count(*)  published ,year(created_at) year, monthname(created_at) month')

And this is My Controller COde

 $archives = Post::latest()->archives()->get();

and this is my error

SQLSTATE[42000]: Syntax error or access violation: 1055 Expression #3 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'homestead.posts.created_at' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by (SQL: select count(*) published ,year(created_at) year, monthname(created_at) month from `posts` group by `year` order by `created_at` desc)

Please sign in or create an account to participate in this conversation.

Laracasts Mascot

Hi, Have We Met Yet?

Did you know that, in addition to the forum, Laracasts includes well over 1000 lessons on modern web development? All for the price of one lunch out per month.

Sign Me Up


Reply to

Use Markdown with GitHub-flavored code blocks.