Level 67
try explicitly selecting created_at instead of just *.
* is of course "get all", but mysql doesn't know the column names in advance so it can mess up some things where named columns are used.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I want to group my data by date and need to use created_at date. But there I get permanently this error:
SQLSTATE[42000]: Syntax error or access violation: 1055 Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'laravelapp.items.id' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by (SQL: select * from `items` group by DATE_FORMAT(created_at, '%Y-%m-%d'))
My method is:
public function scopeUserArchive($query)
{
return $query->select('*')
->groupBy(DB::raw("DATE_FORMAT(created_at, '%Y-%m-%d')"));
}
How can I fix that to get grouped data?
Please or to participate in this conversation.